Repository navigation
Description
Expose Test Explorer's aggregate test counts as an MCP tool.
Proposed tool
test_stats — returns passed / failed / skipped / not-run counts for the current Test Explorer session.
Implementation notes
Public, supported API in Microsoft.VisualStudio.TestWindow.Interfaces.dll:
namespace Microsoft.VisualStudio.TestWindow.Extensibility;
public interface ITestExplorerStatsService
{
TestExplorerStats TestExplorerStats { get; }
bool IsTestExplorerStatsServiceRunning { get; }
event EventHandler<TestExplorerStats> TestExplorerStatsChanged;
}
public struct TestExplorerStats
{
public int PassedTestCount { get; }
public int FailedTestCount { get; }
public int SkippedTestCount { get; }
public int NotRunTestCount { get; }
}MEF-exported by Microsoft.VisualStudio.TestWindow.Data.TestExplorerStatsService (in Microsoft.VisualStudio.TestWindow.dll) with [Export(typeof(ITestExplorerStatsService))], so resolve it via:
var componentModel = await VS.GetServiceAsync<SComponentModel, IComponentModel>();
var stats = componentModel.GetService<ITestExplorerStatsService>();Things to handle
- Check
IsTestExplorerStatsServiceRunningbefore reading. The service isn't live until Test Explorer has initialized. Return a clear "Test Explorer not initialized" result rather than reporting four zeros, which would be indistinguishable from a real empty run. - Consider having
test_run_all/test_runfrom feat(tools): add test run and debug tools with completion tracking #101 fold the post-run stats into their own response, so the agent doesn't have to make a second call after every run. TestExplorerStatsChangedis available if we ever want push-based reporting.
Scope note
This is counts only. There is no public API for the list of individual failed/un-run test names — see #95 for the details on why (internal types gated behind InternalsVisibleTo on Microsoft's strong-name key).
Assembly reference
Same as #101 — reference Microsoft.VisualStudio.TestWindow.Interfaces.dll from the VS install directory at 17.0.0.0 with CopyLocal=false.
Activity