In this article, we are going to configure our Jenkins build server to execute the unit tests in the project during the build. Thus, if the unit tests fail but the code compiles, the build will be marked as unstable. The NUnit plugin, displaying the test results, also lets us to review test statistics compared between builds.
The Jenkins installation that we are going to use, already has the following components set up:
- MSBuild and Git, was deployed in the article Building a Build Server – Building your first C# project with Jenkins
- Cygwin with unzip and wget, and NAnt was deployed in the article Building a Build Server – Installing NAnt
During the example, we are going to build our favorite test project, JenkinsHelloWorld. This project is located at https://github.com/atzimler/JenkinsHelloWorld.git. Feel free to us any other project, if you are not afraid to investigate project problems during the Jenkins setup. As an alternative solution, you can follow along with the test project and then switch your known to work Jenkins configuration to build your project.
Installing NUnit console runner on the build server
Log on into the build server, open a Cygwin terminal and execute the following commands:
cd /tmp mkdir NUnit.org cd NUnit.org wget https://github.com/nunit/nunit-console/releases/download/3.6/NUnit.Console-3.6.0.zip unzip NUnit.Console-3.6.0.zip rm NUnit.Console-3.6.0.zip cd /tmp mv NUnit.org /cygdrive/c cd /cygdrive/c icacls NUnit.org /T /Q /C /RESET |
Install the NUnit plugin
Having the NUnit plugin installed on Jenkins, will provide the opportunity to analyze the test results. To do this, open your main Jenkins page, go to the Manage Jenkins / Manage Plugins menu, and in the Available section select the NUnit plugin and install it.
Configure the test project
Create a new project in Jenkins named NUnitHelloWorld. For the project template use Freestyle project. The configuration of the project is the following:
Source Code Management
Use Git source code management with
Repositories |
|
Repository URL |
|
Branches to build |
|
Branch specifier (blank for ‘any’) |
*/master |
Repository browser: |
(Auto) |
Build
Build a Visual Studio project or solution using MSBuild |
|
MSBuild version |
MSBuild 14.0 |
MSBuild file |
NUnitHelloWorld/NUnitHelloWorld.csproj |
Execute NAnt build |
|
NAnt Version |
NAnt-0.92 |
NAnt Build File |
NUnitHelloWorld.xml |
Targets |
tests |
Post-build Actions
Publish NUnit test result report |
|
Test report XMLs |
NUnitHelloWorld/bin/Debug/TestResult.xml |
Next time, we are going to set up our build server to mark assemblies with the build number, so that we can identify later, which build was executed when a problematic binary is investigated for bugs. Please share if you find this article useful. For updates, you can follow me on Twitter or LinkedIn.
No comments yet.