简体   繁体   English

Mac OSX上MonoDevelop Unity版本的代码覆盖率

[英]Code Coverage for MonoDevelop Unity version on Mac OSX

So here is the context : 所以这是上下文:

  • I'm testing an application with NUnit on MonoDevelop (the Unity Version). 我正在MonoDevelop(Unity版本)上使用NUnit测试应用程序。

  • I do not use UnityTestTools. 我不使用UnityTestTools。

  • I'm working in C# 我在用C#工作

My problem : 我的问题 :

I'm looking for a solution to get my code coverage. 我正在寻找一种解决方案来覆盖我的代码。 I actually heard about MonoCov but i have no idea how to install it on my OSX. 我实际上听说过MonoCov,但是我不知道如何在OSX上安装它。 I also search for this options in MonoDevelop and i kept a look at some post on StackOverFlow but no i didn't find any solution for my particular case. 我也在MonoDevelop中搜索此选项,并在StackOverFlow上查看了一些帖子,但没有找到针对我的特殊情况的任何解决方案。

So does anyone has a solution ? 那么有人有解决方案吗?

Depends upon which version of Mono is actually running the tests : 取决于实际运行测试的Mono版本

ie Which Mono version is running your nunit tests, if using the nunit embedded via MonoDevelop, thus you are using the Mono that is running MonoDevelop. 例如,如果使用通过MonoDevelop嵌入的nunit,则哪个Mono版本正在运行您的nunit测试,因此您正在使用运行MonoDevelop的Mono。 If your tests are shelling out to mono or loading a separate app domain, which mono is used for unit-runner/console, etc... 如果您的测试要使用Mono或加载单独的应用程序域,则该Mono用于单元运行器/控制台等。

Why? 为什么? Older versions (3.x) include the internal cov profiler, but in newer versions this has been replaced by the code coverage filter. 较旧的版本(3.x)包含内部cov探查器,但是在较新的版本中,它已被代码覆盖率过滤器取代

To use the older monocov profiler you add the mono option "--profile=monocov" when 'debug' running your program.exe (via nunit runner, cmdline, etc..). 要使用较旧的monocov分析器,请在“调试”运行program.exe时(通过nunit运行器,cmdline等)添加单声道选项“ --profile = monocov”。 This will generate a "program.exe.cov" file that can be loaded in the MonoCov gui. 这将生成一个“ program.exe.cov”文件,可以将其加载到MonoCov gui中。

Newer mono versions use the profiler coverage filter "--profile=log:coverage" that produces output like the following and does not have a gui like MonoCov, it produces plain text: 较新的mono版本使用探查器覆盖率过滤器“ --profile = log:coverage”,它产生如下输出,并且没有像MonoCov这样的gui,它会产生纯文本:

Coverage Summary:
    xCorFlags (/Users/administrator/code/corflags/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)

Disclaimer: That is from my own blog post 免责声明:那是我自己的博客文章

If you are using an older version of Mono (due to Unity?, which version are they using now?), then the movcov profiler 'should' work and produce the .cov files. 如果您使用的是Mono的旧版本(由于Unity ?,现在使用的是哪个版本?),那么movcov分析器“应该”工作并生成.cov文件。 At that point you just need the MonoCov Gui that can be built from source (update the following to match your OS-X env): 到那时,您只需要可以从源代码构建的MonoCov Gui(更新以下内容以匹配您的OS-X env):

# 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.3/lib:/Library/Frameworks/Mono.framework/Versions/4.0.3/lib/pkgconfig:$PKG_CONFIG_PATH
export 
# 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

Disclaimer: This is from another blog post of mine . 免责声明:这是从另一篇博客中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM