1

I use Visual Studio 2015 with NUnit 2.6, and I'm able to run my unit tests from the UI and see the code coverage in Visual Studio. -- My solution has about 10 projects in it.

I'd like to be able to script this process and invoke it from the command line, but when I'm looking through the NUnit command line arguments, I'm not seeing anything related to code coverage. And the documentation is not appearing to be very friendly here.

What specific command-line arguments should I use to run all of the NUnit unit tests in my solution, from the command line, and have it report a code coverage number (preferably in an output file that's in a machine readable format -- such as XML or JSON)?

svick
  • 236,525
  • 50
  • 385
  • 514
BrainSlugs83
  • 6,214
  • 7
  • 50
  • 56

1 Answers1

-2

Below is a part of the script that execute the nunit test via a command prompt.

mkdir %cd%\TestResults   
"E:\tools\NUnit-3.2.1\bin\nunit3-console.exe" ".\path\to\the assembly file some.dll" "--result:.\TestResults\TestResult.xml;format=nunit2"

I am using this in our continuous integration, and there was a compatibility issue (with a downstream step, that processes the data for publishing) so i had to convert the output file into nunit2 format output file.

NOTE: the output file will not include the code coverage stats though. You have to pass this file to a tool like SONARQube to get that stats, IMHO

OK999
  • 1,353
  • 2
  • 19
  • 39
  • 1
    Yeah, that will execute the tests -- but the question is specifically how to get code coverage in the output results. -- Can you update your answer to specifically address the question of code coverage? -- What is SONARQube and why would it be required? -- In the Visual Studio Test Explorer you just click on "Run"->"Analyze Code Coverage for All Tests", and it just works. -- That's what I would like to automate. – BrainSlugs83 Sep 28 '16 at 21:37
  • Nunit does not provide any code coverage Stats. SonarQube has nothing to do with unit tests or code coverage it is just a tool visualize results generated by other tools such as nunit (only pass-fail count), msbuild related issues, and code coverage data. Check https://stackify.com/code-coverage-tools/ for code coverage related tools or search online. – Devesh Dec 16 '20 at 06:25