Thursday, January 5, 2017

Running MsTest unit tests for your .NET Core code

To be able to run unit tests for your .NET Core code, Microsoft created a new version of the MSTest Framework with support for .NET Core. This version is still in preview yet but provides both testing support from the commandline(through dotnet test) and through Visual Studio.

To get up and running I followed the steps as described here: https://github.com/dotnet/docs/blob/master/docs/core/testing/using-mstest-on-windows.md . However when I tried to run the tests, the Test Explorer in Visual Studio remained empty and no tests were discovered.

What went wrong?

I made a stupid mistake as I only added the MSTest.TestFramework NuGet package. This package contains the Test Attributes and Assertions. To be able to run the tests you also need a Test Adapter and test runner which are part of the dotnet-test-mstest NuGet package. After adding this package, my tests were finally discovered. Problem solved!

From the project.json:

"dependencies": {
   "dotnet-test-mstest": "1.1.2-preview",
   "Marten": "1.2.4",
 
"MSTest.TestFramework": "1.0.8-rc"
},

No comments: