Getting coverage of unit tests in a Mono project

If you want to perform coverage analysis of unit tests in a Mono project, you have the following options:

  • Use dotCover integrated in Visual Studio.
  • Use dotCover integrated in JetBrains Rider.
  • Use dotCover console runner.
    There’s a separate command for getting coverage in Mono projects: cover-mono or just mono.
    For example, we want to get coverage of xUnit tests in some project:
    dotCover.exe mono --output=myRep.html --reportType=HTML -- ../../../packages/xunit.runner.console.2.4.1/tools/net472/xunit.console.exe xUnitTests.dll -noappdomain
    • --output=myRep.html --reportType=HTML tells dotCover to generate a coverage report in the HTML format.
    • At the end, after the double dash --, we specify a path to xUnit console runner (in our example, it is referenced by the project) and a path to a .dll with tests.
    • If you have more than one Mono installations, you must use cover command and specify a path to the desired installation in the --targetExecutable argument.
    • -noappdomain tells the xUnit runner to not use app domains when running test code. 

Console runner known issues:

  • It is not possible to profile child processes. As a result, it is not possible to get coverage of NUnit tests (NUnit runs tests in its child processes by default).
  • If code runs in a child domain, you’ll get zero coverage. That’s why it’s important to specify the -noappdomain argument when getting coverage of Mono tests using xUnit console runner.
  • Default coverage filters for filtering out system and unit testing framework assemblies do not work: you will see these assemblies in coverage results.
  • It’s not possible to merge snapshots.
0 out of 0 found this helpful

Please sign in to leave a comment.

Have more questions?

Submit a request