microsoft / VSSDK-Extensibility-Samples

Samples for building your own Visual Studio extensions
http://aka.ms/extendvs
MIT License
1.22k stars 452 forks source link

Test (Explorer) events #268

Open djfoxer opened 2 years ago

djfoxer commented 2 years ago

Hi, where Can I find details about subscribing to the Tests results (from Test Explorer) ? Just want to know when Tests Failed or Passed,

tonyhallett commented 11 months ago

from the vstest repo

This mentions some extensibility points https://github.com/microsoft/vstest/blob/main/docs/RFCs/0001-Test-Platform-Architecture.md

The extension I work obtains this information via reflection. We export an ITestContainerDiscoverer and handle the StateChanged event specifically looking for the TestOperationStates.TestExecutionFinished. The IOperation can be reflected to obtain TotalTests and FailedTests. https://github.com/FortuneN/FineCodeCoverage/blob/e5eff797294cb27be86f83fe1644d133af87e5fe/SharedProject/Impl/TestContainerDiscovery/TestOperationFactory.cs#L31 The extensibility interfaces were obtained from https://www.nuget.org/packages/Microsoft.VisualStudio.TestWindow.Interfaces

This information can probably be obtained by adding a DataCollector https://www.nuget.org/packages/Microsoft.TestPlatform.ObjectModel

The Initialize method receives DataCollectionEvents that you can subscribe to - TestCaseEnd args has a TestOutcome property of enum type

public enum TestOutcome
{
    /// <summary>
    /// Test Case Does Not Have an outcome.
    /// </summary>
    None = 0,

    /// <summary>
    /// Test Case Passed
    /// </summary>
    Passed = 1,

    /// <summary>
    /// Test Case Failed
    /// </summary>
    Failed = 2,

    /// <summary>
    /// Test Case Skipped
    /// </summary>
    Skipped = 3,

    /// <summary>
    /// Test Case Not found
    /// </summary>
    NotFound = 4,
}

This is not the correct repo and this issue should be closed as this repo is for ( samples ) vs extensibility and you are requesting information on a particular visual studio extension.