Search code examples
visual-studiotestingvisual-studio-2015testcasevsix

How to create custom test case in TestWindow in VS2015


How I can create custom test case in VSIX extension for Visual Studio 2015?

In older version of Visual Studio I was using namespaces

  • Microsoft.VisualStudio.TestPlatform
  • Microsoft.VisualStudio.TestWindow
  • Microsoft.VisualStudio.TestWindow.Core
  • Microsoft.VisualStudio.TestWindow.Interfaces

but these namespaces are in VS2015 (Community) unavailable. Is there any alternatives to create custom test cases parsed from my specific format in VSIX extension?


Solution

  • In recent versions of Visual Studio (2012 and later), they added native support for custom test engines. To write one you would use the following interfaces (which have no documentation to speak of) in the Microsoft.VisualStudio.TestPlatform.ObjectModel namespace:

    1. ITestContainer – Represents a file that contains tests
    2. ITestContainerDiscoverer – Finds all files that contain tests
    3. ITestDiscoverer – Finds all tests within a test container
    4. ITestExecutor – Runs the tests found inside the test container

    More Information:

    There are some tutorials(1)(2) that give step-by-step instructions and example code that use the APIs mentioned above. Due to the involved nature, I'm not going to repost the entire tutorials here. Note, while the posts were originally written against 2012RC, they are still valid for 2012 RTM, 2013, and 2015.