.NET NUnit Build Step Example
I don't seem to find HelloWorld examples to setup build with integrated unit tests.
I have absolutely simple Solution with two .NET Framework 4.7.2 projects: MyProject and MyProject.Tests. The latter contains NUnit tests for MyProject. NUnit 3.12 and NUnitTestAdapter 3.12. No need to say that all unit tests run pass in VS2017.
In TC 2019.1 I have setup and run a build with 2 steps: first using Visual Studio (sln) runner to build MyProject and second to copy the build result to the network. All work.
Where can I find an example to add the step to run Unit tests from MyProject.Tests for my setup above? All I need is build, run tests and if build and tests succeed copy build result to network. I tried to browse through documentation, but all of it seems to refer to super complicated and twisted setups.
Thanks.
Please sign in to leave a comment.
Hello!

I`ve created a sample NUnit step definition below which has a minimal setup for the tests to run:
Specifically, as you have mentioned you use NUnit 3, I suggest to install NUnit Console first (https://www.jetbrains.com/help/teamcity/installing-agent-tools.html) which will also gather the required dependencies. Once that is done, configure the step in a manner similar to above with "Run tests from" pointing to the specific assemblies or wildcards, relative to the checkout folder (above example assumes that Nunit.Sample.Assembly.dll is placed into the checkout directory root during the build).
For the alternative approaches on running NUnit, please have a look at this article: https://www.jetbrains.com/help/teamcity/getting-started-with-nunit.html
It has covered the cases with direct command-line execution, MSBuild, and details on NUnit step advanced usage.
Please let me know if there is anything specific you`d like details on and I will gladly assist.
@... thank you for your reply! Shall I assume Nunit.Sample.Assembly.dll in my case would be SomeRelativePathInCheckoutFolder/ MyProject.Tests.dll (I believe they are kept separate so tests don't get into same release directory)? To get MyProject.Tests.dll built I assume I have to add MyProject.Tests.dll to the Targets to build in my current build step which now only has MyProject:Rebuild? Am I correct here?
Yes, the first part would be to ensure that the MyProject.Tests produces some output for NUnit console to pick up, and once it`s available, you may set up NUnit runner on RelativePath/To/<TestAssembly>. I believe that the output path for each project is governed by the settings found in .csproj, so it`s best to check the relative path MyProject.Tests will try to use at the project configuration.
Please let me know if this approach works for you!