Skip to content

Instantly share code, notes, and snippets.

@kelvinrfr
Forked from krishnaanaril/CoreTest.ps1
Created June 16, 2020 19:29
Show Gist options
  • Save kelvinrfr/fd5a8a55cd3261d9927fb878a22c03ce to your computer and use it in GitHub Desktop.
Save kelvinrfr/fd5a8a55cd3261d9927fb878a22c03ce 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