In TeamCity you can’t use the usual NUnit Runner to run .NET Core unit tests. At least I couldn’t get it to work. I’m sure this will be fixed in the future but for now the below works for me. I got lots of inspiration from this TeamCity blog post.
For this example I’ll use the NConstraints project. It contains a .NET Standard project (SaturdayMP.Constraints) that we want to test and two .NET Core Test projects (SaturdayMP.Constratints.Test and TestClient).
In TeamCity I created a project with the usual first two steps of NuGet Install and Compile.
If you read the TeamCity blog post, the one I got my inspiration from, then you probably noticed it used the .NET Core Runner to compile the project. You might have had to do this when the TeamCity blog post was first written but now using the Visual Studio Runner will compile .NET Core projects.
Then install the plugin by clicking on Administration in the top right then Plugins List on the bottom left.
Then click Upload Plugin Zip link and choose the plugin zip file you just downloaded.
Once the upload is complete you should see something similar to the screen shot below.
The plugin is uploaded but before it’s active you need to reboot TeamCity. In my case I just rebooted the server.
Once the reboot is complete you can check that the plugin installed correctly by going to an agent with Visual Studio 2017 installed.
Once on the agent navigate to the parameters page and you should see something similar to the below screen shot.
If you don’t see the DotNetCli listed then you either forgot to reboot TeamCity, the plugin didn’t install correctly, or you don’t have .NET Core installed on you build agent.
Now that the plugin is installed we can go back to our project and add the unit test build step. Add a new build step and in the runner type pick .NET CLI (dotnet). Then in the command drop down pick test and finally enter the paths to your projects. If you have several projects you can use wildcards.
If you don’t see all the options in the screen shot above them make sure to click Show Advanced Options. In my case I also enabled code coverage at the bottom of the list.
Now when we build the tests should get executed. You can see the results of the tests in the build log or the tests tab of the build results.
As I said at the beginning I’m sure the NUnit Runner will be updated to handle .NET Core but use the above for now.
P.S. – R.I.P. Tom Petty.