Run xUnit.net tests with dotCover coverage: http://www.wwwlicious.com/2015/09/25/teamcity-dotcover-xunit-at-last/
*
*
*
*Tests
]]>
System.CodeDom.Compiler.GeneratedCodeAttribute
System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
System.ObsoleteAttribute
]]>
$xunit
$xunitArg
$workingDir
$dotCoverFilter
$dotCoverAttributeFilter
"@
# Avoid BOM http://stackoverflow.com/questions/5596982/using-powershell-to-write-a-file-in-utf-8-without-the-bom
$encoding = New-Object System.Text.UTF8Encoding -ArgumentList $false # no byte order mark
[System.IO.File]::WriteAllText($settingsFileName, $settingsXml, $encoding)
Write-Output "Wrote coverage parameters file to ${settingsFileName}: $settingsXml"
## Add process filters if specified
if ($dotCoverSkipProcesses) {
$processFilters = "/ProcessFilters=-:$([System.String]::Join(';-:', $dotCoverSkipProcesses.Split(@(',',';'), [System.StringSplitOptions]::RemoveEmptyEntries)))"
}
## Run coverage
$dotCover = Join-Path $dotCoverExecutable "dotCover.exe"
$dotCoverArgs = " cover $settingsFileName /LogFile=$coverageLogFileName /ReturnTargetExitCode $processFilters"
Write-Output "##teamcity[message text='dotCoverExecutable: $dotCoverExecutable']"
Write-Output "##teamcity[message text='dotCoverArgs: $dotCoverArgs']"
$command = "$dotCover $dotCoverArgs"
Write-Output "Executing dotCover via command: $command"
Invoke-Expression $command
if ($LASTEXITCODE -ne 0) {
throw New-Object System.Exception "dotCover run failed with error code $LASTEXITCODE"
}
## Report coverage results and output build artifacts
Write-Host "##teamcity[dotNetCoverage dotcover_home='$dotCoverExecutable']"
Write-Output "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='$outputFile']"
Write-Output "##teamcity[publishArtifacts '$settingsFileName']"
Write-Output "##teamcity[publishArtifacts '$coverageLogFileName']"
Write-Output "##teamcity[publishArtifacts '$outputFile']"
## Optional generate report
if ($dotCoverReportEnabled) {
$reportCommand = "$dotCover report /source=$outputFile /output=$dotCoverReportFile /reportType=$dotCoverReportType"
Write-Output "Creating dotCover report via command: $reportCommand"
Invoke-Expression $reportCommand
Write-Output "##teamcity[publishArtifacts '$dotCoverReportFile']"
}
}
else {
## run xunit without coverage
$xunitOnlyCommand = "$xunit $xunitArg"
Write-Output "Running unit tests without coverage via command: $xunitOnlyCommand"
Invoke-Expression $xunitOnlyCommand
}
}
catch {
Write-Output "##teamcity[buildStatus text='$_' status='FAILURE']"
Write-Output "##teamcity[message text='$_' status='ERROR']"
exit 1
}]]>