BLOG
Test Case Association to xUnit, NUnit, and MSTestV2 Tests is available in Visual Studio 2017 15.7.1
11/20/2018 Update - The Associate to Test Case option is working again in 15.9.2! I didn't get a chance to try 15.9.1 to know if it worked with that version or not. I'll keep this updated if the behavior changes.
9/04/2018 Update - The Associate to Test Cases option has been disabled again in 15.8.0, 15.8.1, and 15.8.2. Other workarounds are to reference the MSTestV1 (Microsoft.VisualStudio.QualityTools.UnitTestFramework) and remove MSTestV2 references when doing the associate or use the API for doing the association.
The "truth center" of detailed requirements for projects should be represented as tests or sometime also refereed as executable requirements. Traditionally we have accomplished this using the following "Test Case First" process.
User Story (Desirement) > Acceptance Criteria (Informal detailed requirements) > Test Cases (Work Item with Given, When, Then)
We then create the UI or API automated functional test and associate the automated test with the Test Case Work Item. This gave us a great amount management and reporting capabilities for test cases and provided a consistent way to work with manual and automated tests. However, one downside to this approach is that this has only worked with MSTestV1. Other test frameworks have become more popular such as xUnit and NUnit and even Microsoft introduced MsTestV2. The problem is that none of these other frameworks would work. The Associate Test Case Option has been disabled. Note: Even though these are unit test testing frameworks, these frameworks are often used for writing and running functional UI and APIs through code and linking to other testing tools like TestArchitect and SoapUi.
The DevOps movement has been pushing activities like testing upstream to the developers with the focus to automate all tests. One could argue that having a Test Case work item and an automated test with the details of the requirements is redundant. Which is the truth? As teams want to move faster, they skip the test case and use the automated test and test results as the test case itself. VSTS allows for the test results to be associated to requirements to still provide traceability and to be able to show test quality at the requirement level.
With Visual Studio not supporting the ability to associate test cases to xUnit, NUnit, or MSTest V2 tests, this has forced teams to abandon the test case first approach and to use the requirements. I have been following this thread on Visual Studio Developer Community website where it was mentioned that this functionality is available with Visual Studio 15.7.1. I'm excited to report that you can now associate Test Cases to all three of these frameworks and possibly other others. I created a Unit Testing Solution with 3 projects representing each of these tools. I was able to associate all of the tests and run them through VSTS using the Test Plan option.
Now you can choose the approach that best fits your process and not base it on a tool limitation.
![unittest-comparison-project.jpg](https://cdn.prod.website-files.com/5f4fbc868a9c45ad11ad8c9e/60a6f3cc22d7736ea4812eb9_unittest-comparison-project.jpeg)
In VSTS, the Visual Studio Test task has the option to run tests by Test Plan / Test Suite / Test Configuration.
![visualstudio-test-task.jpg](https://cdn.prod.website-files.com/5f4fbc868a9c45ad11ad8c9e/60a6f3cc688faf680b38e028_visualstudio-test-task.jpeg)
![vsts-test-results-test-suite.jpg](https://cdn.prod.website-files.com/5f4fbc868a9c45ad11ad8c9e/60a6f6912f457934fb1940ef_vsts-test-results-test-suite.jpeg)
![test-case-results-chart.jpg](https://cdn.prod.website-files.com/5f4fbc868a9c45ad11ad8c9e/60a6f3cd8640fabbc1cc192b_test-case-results-chart.jpeg)
As always, reach out to me at twitter at https://twitter.com/mikedouglasdev for any questions or comments.