我是一个同时使用OpenCover和ReportGenerator的新手,我正在努力理解如何让它们工作。我使用的是VS.NET 2012“专业版”,这意味着我无法访问内置的单元测试覆盖率工具。我也安装了ReSharper,但不想为'dotCover‘中的另一个工具付费
看起来OpenCover和ReportGenerator将会做我需要的事情,我看到了下载的文档,但是我不太理解。首先,当我下载nuget包的时候,我的目标项目应该是什么?我有一个多层的应用程序,所以我假设我的单元测试项目是正确的,或者这有关系吗?我在文档中看到,我只是指向(我认为)使用命令行命令的解决方案的/bin,所以我甚至不需要将这些下载添加到任何特定的项目中(可能是一个测试工具)。有没有人能告诉我我的理解是否正确?
一旦我安装了它们,我就会尝试获取单元测试覆盖率指标,而该包附带的文档并不像我希望的那样清晰。有没有什么好的博客文章或链接可以一起使用这些工具来获得指标?
发布于 2013-05-18 02:25:03
您不需要将这些添加到特定项目中
我也使用报告生成器和open cover来生成测试覆盖率结果。这是我用来使用opencover生成codecoverage的脚本
"C:\Program Files (x86)\OpenCover\OpenCover.Console.exe“-register:user -target:"C:\Program Files (X86)\ Visual Studio 10.0\Common7\IDE\mstest.exe”-targetargs:"/noisolation /testcontainer:\"C:\bin\Debug.dll\“/resultsfile:C:\Reports\MSTest.trx”-filter:"+__“-mergebyhash Studio
请注意,如果您的参数需要转义引号,即向目标进程传递带空格的参数,则可以使用",例如:-targetargs:"c:\program files"
这是我用来运行报表生成器的脚本。
-reports:"C:\Reports\MSTest\projectCoverageReport.xml“
C:\ReportGenerator\bin\ReportGenerator.exe -targetdir:"C:\Reports\CodeCoverage”
希望这能有所帮助。
发布于 2015-06-19 13:14:48
在使用这些开源工具几年之后,我终于写了一篇关于如何使用OpenCover和ReportCover来生成单元测试覆盖率度量的综合文章。
这篇文章描述了如何创建.bat文件以及执行以下操作所需的命令:
使用输出数据来解释单元测试覆盖率指标生成单元测试指标的输出报告OpenCover
.htm .htmUsing OpenCover and ReportGenerator to get Unit Testing Code Coverage Metrics in .NET
发布于 2017-03-31 02:29:06
感谢@atconway的教程。我对您的.bat脚本进行了一些更新,以方便将来的升级和项目更改。
综上所述,要在NUnit中使用OpenCover,您必须在项目中添加以下这些元素:
这是更新的.bat文件。要运行它,只需编辑“设置”并将脚本保存为项目根目录下的.bat文件即可。
@echo off
REM ** Be sure to install these nugets:
REM ** NUnit.ConsoleRunner
REM ** OpenCover
REM ** ReportGenerator
REM **
REM ** All paths should be entered without quotes
REM ** SET TestResultsFileProjectName=CalculatorResults
SET TestResultsFileProjectName=<ANY_NAME>
REM ** SET DLLToTestRelativePath=Calculator\bin\Debug\MyCalc.dll
SET DLLToTestRelativePath=<VALID_PATH>
REM ** Filters Wiki https://github.com/opencover/opencover/wiki/Usage
REM ** SET Filters=+[Calculator]* -[Calculator]CalculatorTests.*
SET Filters=<VALID_FILTERS>
SET OpenCoverFolderName=OpenCover.4.6.519
SET NUnitConsoleRunnerFolderName=NUnit.ConsoleRunner.3.6.1
SET ReportGeneratorFolderName=ReportGenerator.2.5.6
REM *****************************************************************
REM Create a 'GeneratedReports' folder if it does not exist
if not exist "%~dp0GeneratedReports" mkdir "%~dp0GeneratedReports"
REM Remove any previous test execution files to prevent issues overwriting
IF EXIST "%~dp0%TestResultsFileProjectName%.trx" del "%~dp0%TestResultsFileProjectName%.trx%"
REM Remove any previously created test output directories
CD %~dp0
FOR /D /R %%X IN (%USERNAME%*) DO RD /S /Q "%%X"
REM Run the tests against the targeted output
call :RunOpenCoverUnitTestMetrics
REM Generate the report output based on the test results
if %errorlevel% equ 0 (
call :RunReportGeneratorOutput
)
REM Launch the report
if %errorlevel% equ 0 (
call :RunLaunchReport
)
exit /b %errorlevel%
:RunOpenCoverUnitTestMetrics
"%~dp0packages\%OpenCoverFolderName%\tools\OpenCover.Console.exe" ^
-register:user ^
-target:"%~dp0packages\%NUnitConsoleRunnerFolderName%\tools\nunit3-console.exe" ^
-targetargs:"--noheader \"%~dp0%DLLToTestRelativePath%\"" ^
-filter:"%Filters%" ^
-mergebyhash ^
-skipautoprops ^
-excludebyattribute:"System.CodeDom.Compiler.GeneratedCodeAttribute" ^
-output:"%~dp0GeneratedReports\%TestResultsFileProjectName%.xml"
exit /b %errorlevel%
:RunReportGeneratorOutput
"%~dp0packages\%ReportGeneratorFolderName%\tools\ReportGenerator.exe" ^
-reports:"%~dp0GeneratedReports\%TestResultsFileProjectName%.xml" ^
-targetdir:"%~dp0GeneratedReports\ReportGenerator Output"
exit /b %errorlevel%
:RunLaunchReport
start "report" "%~dp0GeneratedReports\ReportGenerator Output\index.htm"
exit /b %errorlevel%https://stackoverflow.com/questions/16591486
复制相似问题