How to correctly specify arguments of a covered application for the console runner

When running coverage analysis using the dotCover console runner, typically you should pass some arguments to the covered application. To do this, you should:

  • either specify the arguments at the end of the command line after double dash --
  • or use the --targetArguments parameter.

Specifying args after double dash --

For example, to run coverage analysis of unit tests in a .NET Core project:

dotCover.exe dotnet --output=myRep.html --reportType=HTML -- test

test passed at the end of the command line is an argument of dotnet (the target of coverage analysis). This is an equivalent for the following command line:

dotCover.exe dotnet  --targetArguments=”test” --output=myRep.html --reportType=HTML

Note that when you pass target arguments after double dash, no characters escaping is needed. dotCover does not process these arguments in any way.

Specifying args in the --targetArguments parameter

For example, to get coverage of NUnit tests in some MyTests.dll assembly:

dotcover cover --targetExecutable="D:\NUnit\nunit-console.exe" --targetArguments="D:\MyProject\MyTests.dll" --output=report.html --reportType=HTML

Arguments with relative paths

By default, if arguments contain relative paths, the console runner converts them to the absolute ones according to the following rules:

  • Relative paths specified in an XML configuration file are considered relative to the location of this file.
  • Relative paths specified in the command line are considered relative to the current working directory.

For example, you want to cover E:\Tests\Builds\MyTests.dll using NUnit. Your current directory is E:\Tests\Builds\.

E:\Tests\Builds>c:\dotCoverCmd\dotcover.exe cover --targetExecutable="C:\Program Files\NUnit 2.6\bin\nunit-console.exe" --targetArguments=".\MyTests.dll /xml=..\Coverage\Cover.xml" --output=CoverageReport.html --reportType=HTML

NUnit will get the following arguments:

E:\Tests\Builds\MyTests.dll /xml=E:\Tests\Coverage\Cover.xml

If you do not want dotCover to analyze target arguments, specify the --analyzeTargetArguments=false argument.

Arguments with spaces and double quotes

There are two general rules you must follow:

  • If a target arguments string contains spaces, you must enclose it in double quotes.
  • All double quotes inside target arguments must be escaped with a backslash.

For example, if you want to pass the following line to your coverage target

“C:\My Application\MyPath” a=10

you should specify the following

--targetArguments=“\”C:\My Application\MyPath\” a=10”

4 out of 12 found this helpful
1 comment

Hi! What should I do if I need to cover multiple dlls.?








Please sign in to leave a comment.

Have more questions?

Submit a request