https://www.swtestacademy.com/jenkins-dotnet-integration/
8) Unit Tests and Test Coverage Settings
Download and extract OpenCover under “C:Tools” folder.
Also, generate latest OpenCovertoCoberturaConverter.exe under “C:ToolsCobertura”.
Install latest version of NUnit.
And finally, add an “Execute Windows batch command” step and write a command as follows according to your project. For targettargs, set your Unit Test’s dll file.
Note: There is a problem to publish Nunit 3 test results with latest NUnit Jenkins plugin. Thus, I changed NUnit 3 format to NUnit 2 format by adding “format=nunit2” in below script.
Below script, automatically run all of your unit tests and create TestResults.xml file under workspace also it runs test coverage and creates Coverage.xml under workspace folder.
Script:
“C:ToolsopencoverOpenCover.Console.exe” -register:user -target:”C:Program Files (x86)NUnit.org unit-console unit3-console.exe” -targetargs:”C:JenkinsProjects{YOUR PROJECT PATH}inDebugKariyerNet.Business.ECommerce.UnitTests.dll –result=TestResult.xml;format=nunit2″ -filter:+
[*]* -output:Coverage.xml