Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Created July 5, 2019 04:42
Show Gist options
  • Save krishnaanaril/3009aa8752754335435abd018e079965 to your computer and use it in GitHub Desktop.
Save krishnaanaril/3009aa8752754335435abd018e079965 to your computer and use it in GitHub Desktop.
Powershell script for running dotnet-core unit tests and generate report.
param(
[Parameter(Mandatory=$true)]
[string]$testProjectPath,
[Parameter(Mandatory=$true)]
[string]$testSettingsPath,
[Parameter(Mandatory=$true)]
[string]$testResultsFolder
)
<#
echo "Test Project Path" $testProjectPath
echo "Test Settings Path" $testSettingsPath
echo "Test Results Folder" $testResultsFolder
#>
try {
if (-not (Test-Path $testProjectPath))
{
throw [System.IO.FileNotFoundException] "$testProjectPath not found."
}
if (-not (Test-Path $testSettingsPath))
{
throw [System.IO.FileNotFoundException] "$testSettingsPath not found."
}
if (-not (Test-Path $testResultsFolder))
{
throw [System.IO.FileNotFoundException] "$testResultsFolder not found."
}
dotnet test $testProjectPath --settings:$testSettingsPath
$recentCoverageFile = Get-ChildItem -File -Filter *.coverage -Path $testResultsFolder -Name -Recurse | Select-Object -First 1;
write-host 'Test Completed' -ForegroundColor Green
C:\Users\krishnamohan\.nuget\packages\microsoft.codecoverage\15.9.0\build\netstandard1.0\CodeCoverage\CodeCoverage.exe analyze /output:$testResultsFolder\MyTestOutput.coveragexml $testResultsFolder'\'$recentCoverageFile
write-host 'CoverageXML Generated' -ForegroundColor Green
dotnet C:\Users\krishnamohan\.nuget\packages\reportgenerator\4.1.10\tools\netcoreapp2.1\ReportGenerator.dll "-reports:$testResultsFolder\MyTestOutput.coveragexml" "-targetdir:$testResultsFolder\coveragereport"
write-host 'CoverageReport Published' -ForegroundColor Green
}
catch {
write-host "Caught an exception:" -ForegroundColor Red
write-host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red
write-host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment