如何在Mac上构建和使用Monocov

时间:2015-06-15 14:05:46

标签: macos mono

我需要以下任务的帮助: 我想测量单声道组件的测试覆盖率。为此,我想使用MonoCov。不幸的是,我的知识还不足以在Mac上构建工具。即使这article也无法帮助我。是否有人设法在Mac上构建monocov并使用它来测量测试覆盖率?

1 个答案:

答案 0 :(得分:3)

好吧,看来Xamarin删除了'内部'cov分析器,而且单声道不会产生任何输出(除了单声道实际加载共享库,没有函数被调用),因为api已经改变了。

他们在核心日志分析器中添加了代码覆盖过滤器(2015年4月7日),但我找不到任何已发布的文档(?)。启用它很容易。

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

关于cov删除和日志覆盖过滤器添加的Git日志信息:

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

如果您仍在使用Mono 3.x,那么我的原始回复将起作用:

这是一些旧代码......

如果您安装了Mono 4.0.x,以下是编译MonoCov的步骤。 gui工作正常,不确定实际的分析器(共享分析库)是否正常工作。

# Clone the MonoCov repo
git clone https://github.com/mono/monocov.git MonoCov
cd MonoCov
# A really old version of cecil and it not available as a nuget
curl http://go-mono.com/archive/cecil/cecil-0.6-bin.zip -o cecil-0.6-bin.zip
unzip cecil-0.6-bin.zip
# Make sure configure can find the Mono.Option source file
export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/4.0.1/lib:/Library/Frameworks/Mono.framework/Versions/4.0.1/lib/pkgconfig:$PKG_CONFIG_PATH
# Config to install to users home dir
/configure --cecil=$PWD/monocov/cecil-0.6/Mono.Cecil.dll --prefix=$HOME/monocov
# Fix Makefile, gmcs no longer exists under Mono 4.x and Makefile is hard coded
sed -i.bak s/gmcs/mcs/g Makefile
# Pass -m32 to make since OS-X Mono framework is still 32-bit
CC="cc -m32" make
# Install does not properly create bin dir, do it before the first install
mkdir $HOME/monocov/bin
# Install..
make install
# Update your path

运行gui

# GUI Framework DllNotFoundException fix (if needed)
export DYLD_FALLBACK_LIBRARY_PATH="/Library/Frameworks/Mono.framework/Versions/Current/li b:/usr/local/lib:/usr/lib"
# Update path to include MonoCov
export PATH=$HOME/monconv/bin:$PATH
monocov &

当然,您需要使用配置文件加载到其中来创建MonoCov'cov'文件...