Code coverage on Xamarin Studio

白昼怎懂夜的黑 提交于 2020-01-01 15:32:33

问题


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 ! )


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/32118808/code-coverage-on-xamarin-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!