How to fix unit test discovery in VS 2017 with MSTest V2?
Microsoft Test Framework “MSTest V2” is the evolution of the Microsoft Test Framework and Adapter.
I wanted to try this new framework test by creating a new test project from an empty class library instead of using a MsTest test project and I got in trouble…..
My unit tests were not discovered by Visual Studio 2017.
How did I fix this?
What I have installed
I have installed the following packages:
Then I checked if my unit tests were displayed on Test Explorer and they were not 🙁 , I even tried to run them but I got this message:
What I did to find the issue
There are many reason that can explain this issue, so to know what’s going on I ran the following command line in the unit test project directory:
> dotnet test
It’s the same command that Visual Studio executes but by this way, you will see the precise error if there is an error during execution of the command line:
In my case I knew easily what I missed since the beginning!
I missed the installation of Microsoft.NET.Tests.Sdk package!
I just installed it and I was able to run my tests 🙂
Hope it has helped you 🙂