3

Is there a reliable tool that would help us measure the code coverage of my unit tests? I'm mostly working on Xamarin projects (in Xamarin Studio).

For the sake of not getting heaps of -1, I've looked around but couldn't find something mature enough to be reliable. I don't ask the product to be free (but it's of course better if it is ! )

Gil Sand
  • 5,802
  • 5
  • 36
  • 78

2 Answers2

2

There is the code coverage profiler that is in the Mono 4.x line (since a April 7, 2015 commit).

It does not help you if you doing Mobile testing, but if you are running unit tests on desktop platforms you can supply the profiler options to Mono:

--profile=log:coverage

coverage             enable collection of code coverage data
covfilter=ASSEMBLY   add an assembly to the code coverage filters
                     add a + to include the assembly or a - to exclude it
                     filter=-mscorlib
covfilter-file=FILE  use FILE to generate the list of assemblies to be filtered

In normal "exe" processing, you end up with:

Coverage Summary:
    xCorFlags (/Users/administrator/monocov/lib/xCorFlags.exe) 26% covered (42 methods - 11 covered)
        <Module> ?% covered (0 methods - 1 covered)
        CorFlags.CorFlagsSettings 25% covered (4 methods - 1 covered)
        CorFlags.MainClass 50% covered (2 methods - 1 covered)
        CorFlags.CommandLineParser 40% covered (20 methods - 8 covered)

So, pass the profile options to your cmd line based runner (nunit, xunit, etc..) and you can get an overview of your coverage.

For detailed coverage results and fully integrated to a IDE (like VS), nothing I know about on OS-X/Linux for C# even comes close to the tools available on Windows/.Net. :-(

Commit Information on removal of old mono-cov and the addition of coverage profiler:

Git log info on cov removal and log coverage filter addition:

commit 16570265149730ec6a4760cc0fa34decc1a9d981
Author: Alex Rønne Petersen <alexrp@xamarin.com>
Date:   Tue Apr 7 14:51:27 2015 +0200
        [profiler] Remove old mono-cov profiler.
        We're replacing this with coverage support in the log profiler.

commit e91693fbb87f687a2fdb5a495c945c1872b3066c
Author: iain holmes <iain@xamarin.com>
Date:   Fri Feb 27 10:13:54 2015 +0000
        [cov] Install a coverage filter
SushiHangover
  • 73,120
  • 10
  • 106
  • 165
0

There is no built in code coverage tool but fortunately there are many tools that can help you: What can I use for good quality Code Coverage for C#/.NET?

I use OpenCover with ReportGenerator (https://github.com/danielpalme/ReportGenerator) and I'm really satisfied.

As far as I know there is no way to show covered/uncovered lines inside the IDE.

Community
  • 1
  • 1
Wosi
  • 41,986
  • 17
  • 75
  • 82
  • 1
    OpenCover has SharpDevelop integration, but it is Windows only right now. So I don't think it would work for Xamarin mobile platforms. – Lex Li Aug 20 '15 at 14:59
  • Yeah and sadly I'm developing on a Mac. – Gil Sand Aug 20 '15 at 16:35
  • 1
    Mono has a code-coverage profiler available, not IDE based, but via cmd-line execution "--profile=log:coverage", see my answer to this question for details – SushiHangover Aug 20 '15 at 18:58