Skip to content

Commit

Permalink
Updated unit testing and code-coverage scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Nov 29, 2024
1 parent 6504e1a commit 5717013
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 42 deletions.
2 changes: 1 addition & 1 deletion scripts/coveralls.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $debugDir = Join-Path $binDir "Debug"
$OutputDir = Join-Path $debugDir $targetFramework.InnerText

# Upload code-coverage data to coveralls.io
& dotnet tool run csmacnz.Coveralls --opencover -i opencover.xml `
& dotnet tool run csmacnz.Coveralls --opencover -i coverage.xml `
--repoToken $env:COVERALLS_REPO_TOKEN `
--useRelativePaths `
--basePath $OutputDir `
Expand Down
49 changes: 8 additions & 41 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ param (
[string]
$Configuration = "Debug",
[string]
$GenerateCodeCoverage = "no"
$GenerateCodeCoverage = "false"
)

Write-Output "Configuration: $Configuration"
Expand All @@ -13,51 +13,18 @@ Write-Output ""

[xml]$project = Get-Content UnitTests\UnitTests.csproj

$nugetPackagesDir = Join-Path $Home ".nuget" "packages"

# Get the NUnit.ConsoleRunner executable path
$packageReference = $project.SelectSingleNode("/Project/ItemGroup/PackageReference[@Include='NUnit.ConsoleRunner']")
$consoleRunnerVersion = $packageReference.GetAttribute("Version")

$NUnitConsoleRunner = Join-Path $nugetPackagesDir "nunit.consolerunner" $consoleRunnerVersion "tools" "nunit3-console.exe"

# Get the OutputPath
$targetFramework = $project.SelectSingleNode("/Project/PropertyGroup/TargetFramework")
$OutputDir = Join-Path "UnitTests" "bin" $Configuration $targetFramework.InnerText
$UnitTestsAssembly = Join-Path $OutputDir "UnitTests.dll"

if ($GenerateCodeCoverage -eq 'yes') {
# Get the OpenCover executable path
$packageReference = $project.SelectSingleNode("/Project/ItemGroup/PackageReference[@Include='OpenCover']")
$openCoverVersion = $packageReference.GetAttribute("Version")
$openCoverToolsDir = Join-Path $nugetPackagesDir "opencover" $openCoverVersion "tools"

$OpenCoverProfiler32 = Join-Path $openCoverToolsDir "x86" "OpenCover.Profiler.dll"
$OpenCoverProfiler64 = Join-Path $openCoverToolsDir "x64" "OpenCover.Profiler.dll"
$OpenCover = Join-Path $openCoverToolsDir "OpenCover.Console.exe"

try {
& regsvr32 $OpenCoverProfiler32
} catch {
Write-Output "Failed to register $OpenCoverProfiler32"
}

try {
& regsvr32 $OpenCoverProfiler64
} catch {
Write-Output "Failed to register $OpenCoverProfiler64"
}
if ($GenerateCodeCoverage -eq 'true') {
Write-Output "Instrumenting code..."

Write-Output "Running the UnitTests (code coverage enabled)"
& dotnet AltCover -i="$OutputDir" --inplace -s="System.*" -s="Microsoft.*" -s="NUnit*" -s="AltCover.*" -s="testhost" -s="UnitTests"
# & dotnet AltCover Runner --recorderDirectory=$OutputDir --executable=$NUnitConsoleRunner --summary=O -- --domain:single $UnitTestsAssembly
}

# Run OpenCover
& $OpenCover -filter:"+[HtmlKit]* -[UnitTests]*" `
-target:"$NUnitConsoleRunner" `
-targetargs:"--domain:single $UnitTestsAssembly" `
-output:opencover.xml
} else {
Write-Output "Running the UnitTests"
Write-Output "Running the UnitTests"

# Run OpenCover
& $NUnitConsoleRunner --domain:single $UnitTestsAssembly
}
dotnet nunit $UnitTestsAssembly

0 comments on commit 5717013

Please sign in to comment.