NuGetパッケージ
Microsoft.TestPlatform
Microsoft.DiaSymReader.Native
バッチファイル
@ECHO OFF
SET PJNAME=OpenCoverSample
set filters=+[%PJNAME%]* -[*Test]*
SET TESTDLL=%PJNAME%Tests\bin\Debug\OpenCoverSampleTests.dll
SET TIME2=%TIME: =0%
SET LOGDIR=%DATE:/=-%_%TIME2:~0,2%_%TIME2:~3,2%_%TIME2:~6,2%
SET LOGDIR=results
SET LOGGER=/logger:trx;LogFileName=results\result.trx
SET DIAG=/Diag:OpenCover\results\result.log
SET XMLFILE=OpenCover\%LOGDIR%\OpenCover.xml
SET RESULTSDIRECTORY=/ResultsDirectory:OpenCover
SET VSTESTCONSOLE=packages\Microsoft.TestPlatform.17.7.1\tools\net462\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
SET OPENCOVER=packages\OpenCover.4.7.1221\tools\OpenCover.Console.exe
SET REPORTGENERATOR=packages\ReportGenerator.5.1.24\tools\net47\ReportGenerator.exe
IF NOT EXIST "OpenCover\%LOGDIR%" (
ECHO ======================================================================
ECHO MKDIR OpenCover\%LOGDIR%
ECHO ======================================================================
MKDIR "OpenCover\%LOGDIR%"
)
ECHO ======================================================================
ECHO OpenCover.Console.exe
ECHO ======================================================================
"%OPENCOVER%" -register:user "-filter:%filters%" "-target:%VSTESTCONSOLE%" ^"-targetargs:\^"%TESTDLL%\^" \^"%RESULTSDIRECTORY%\^" \^"%LOGGER%\^" \^"%DIAG%\^"" "-output:%XMLFILE%"
ECHO ======================================================================
ECHO ReportGenerator.exe
ECHO ======================================================================
"%REPORTGENERATOR%" "-reports:%XMLFILE%" "-targetdir:OpenCover\%LOGDIR%\html"
pause
MSBuildタスクでOpenCoverを使用する
<PropertyGroup>
<OpenCoverMSBuildTasksPath>$(MSBuildProjectDirectory)\..\packages\OpenCover.4.6.519\MSBuild</OpenCoverMSBuildTasksPath>
</PropertyGroup>
<Import Project="..\packages\OpenCover.4.6.519\MSBuild\OpenCover.targets"
Condition="Exists('..\packages\OpenCover.4.6.519\MSBuild\OpenCover.targets')"/>
<Target Name="coverage">
<OpenCover
ExcludeByAttribute="System.ObsoleteAttribute"
Filter="+[*]* -[*Tests]*"
Register="True"
Output="bin\Debug\coverage.xml"
Target="..\packages\Microsoft.TestPlatform.15.8.0\tools\net451\Common7\IDE\Extensions\TestPlatform\vstest.console.exe"
TargetArgs="bin\Debug\OpenCoverSampleTests.dll /ResultsDirectory:bin\Debug /logger:trx;LogFileName=coverage.trx /Diag:bin\Debug\coverage.log"
ToolExe="OpenCover.Console.exe"
ToolPath="..\packages\OpenCover.4.6.519\tools\">
<Output TaskParameter="ExitCode" PropertyName="TestExitCode"/>
</OpenCover>
</Target>