Skip to content

Instantly share code, notes, and snippets.

@scottoffen
Created July 25, 2016 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottoffen/25a92f5648fb3981a86b2facf5ed76f6 to your computer and use it in GitHub Desktop.
Save scottoffen/25a92f5648fb3981a86b2facf5ed76f6 to your computer and use it in GitHub Desktop.
Original implementation of OpenCover and Xunit on the Grapevine project
@ECHO OFF
REM OpenCover-xunit.bat
REM Run opencover against xunit tests in your test project and show report of code coverage
Set SearchDirectory=%~dp0Grapevine.Tests\bin\Debug
SET DllContainingTests=%~dp0Grapevine.Tests\bin\Debug\Grapevine.Tests.dll
REM *** IMPORTANT - Change DllContainingTests variable (above) to point to the DLL
REM *** in your solution containing your NUnit tests
REM ***
REM *** You may also want to change the include/exclude filters (below)
REM *** for OpenCover
REM ***
REM *** This batch file should dbe placed in the root folder of your solution
REM *** Before being able to use this to generate coverage reports you
REM *** will need the following NuGet packages
REM PM> Install-Package OpenCover
REM PM> Install-Package ReportGenerator
REM PM> Install-Package NUnit.ConsoleRunner
REM
REM NUnit Test Runner (done this way so we dont have to change the code
REM when the version number changes)
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="xunit.console.exe" SET TestRunnerExe=%%~dpnxa
REM Get OpenCover Executable (done this way so we dont have to change the
REM code when the version number changes)
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="OpenCover.Console.exe" SET OpenCoverExe=%%~dpnxa
REM Get Report Generator (done this way so we dont have to change the code
REM when the version number changes)
for /R "%~dp0packages" %%a in (*) do if /I "%%~nxa"=="ReportGenerator.exe" SET ReportGeneratorExe=%%~dpnxa
REM Create a 'GeneratedReports' folder if it does not exist
if not exist "%~dp0GeneratedReports" mkdir "%~dp0GeneratedReports"
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
REM *** Change the filter to include/exclude parts of the solution you want
REM *** to check for test coverage
"%OpenCoverExe%" ^
-target:"%TestRunnerExe%" ^
-targetargs:"\"%DllContainingTests%\"" ^
-filter:"+[*]* -[*.Tests*]* -[*]*.*Config -[xunit*]*" ^
-mergebyhash ^
-skipautoprops ^
-register:user ^
-output:"%~dp0GeneratedReports\CoverageReport.xml"^
-searchdirs:"%SearchDirectory%"
exit /b %errorlevel%
:RunReportGeneratorOutput
"%ReportGeneratorExe%" ^
-reports:"%~dp0\GeneratedReports\CoverageReport.xml" ^
-targetdir:"%~dp0\GeneratedReports\ReportGeneratorOutput"
exit /b %errorlevel%
:RunLaunchReport
start "report" "%~dp0\GeneratedReports\ReportGeneratorOutput\index.htm"
exit /b %errorlevel%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment