Skip to content

Instantly share code, notes, and snippets.

@christrotter
Created January 27, 2017 21:50
Show Gist options
  • Save christrotter/26bf77e73fffbd1c8f655e3d63f0de6a to your computer and use it in GitHub Desktop.
Save christrotter/26bf77e73fffbd1c8f655e3d63f0de6a to your computer and use it in GitHub Desktop.
Octopus Step Template - Nunit
function PostToSlack {
Param([string]$message)
$slackHook = "$SlackChannel"
$wc = New-Object net.webclient
$wc.UploadString($slackHook, (ConvertTo-Json @{ text = ("$message") }))
}
$enviro = "$enviroShortName"
$nUnitDir = "$NUnitWorkingDirectoryPath\tests\$enviro"
$reportUnitDir = "$NUnitWorkingDirectoryPath\output\ReportUnit\bin"
$exePath = "nunit3-console.exe"
$reportUnitExe = "ReportUnit.exe"
$date = Get-Date -UFormat %Y/%m/%d
$millisecondDate = Get-Date -UFormat %s
[int]$unique = "{0:N0}" -f $millisecondDate
$bucket = "corp-logging"
$resultFileName = "TestResult-$enviro-$unique.xml"
$s3Location = ("/NUnit/appName/{1}/{2}" -f $bucket, $date, $resultFileName)
$siteBucket = "corp-nunitsite"
$reportFileName = "TestReport-$enviro-$unique.html"
$s3Location = ("/NUnit/appName/{1}/{2}" -f $sitebucket, $date, $reportFileName)
Write-Output "We are running NUnit tests..."
$category = @"
'cat == $($NUnitCategory)'
"@
Push-Location "$nUnitDir"
$runNUnit = "& $exePath $NUnitTestAssemblies --output:TestStdOut.txt --err:TestStdErr.txt --where=$category"
Invoke-Expression $runNUnit
$nunitExit = $lastExitCode
Write-Host "Sending the XML to S3..."
Write-S3Object -BucketName $bucket -Key $s3Location -File TestResult.xml
Write-Host "Copying the XML over to ReportUnit's dir..."
Copy-Item -Force TestResult.xml $reportUnitDir\TestResult.xml
Pop-Location
Write-Host "Running ReportUnit.exe..."
Push-Location "$reportUnitDir"
$runReportUnit = "& .\$reportUnitExe TestResult.xml TestResult.html"
Write-Host "Let's execute the ReportUnit XML beautifier..."
Invoke-Expression $runReportUnit
if (!(Test-Path "$reportUnitDir\TestResult.html")) {Write-Host "Cannot find the html file in: $reportUnitDir"}
Copy-Item -Force -Path TestResult.html -Destination TestReport.html # This is some tech-debt around Octopus artifact uploading, it can't upload TestResult.html, but can upload a renamed version of the file.
Write-Host "Copying the Report HTML up to the S3 website..."
Write-S3Object -BucketName $siteBucket -Key $s3Location -File TestReport.html
Pop-Location
if ($nunitExit -ne 0) {
PostToSlack ":onfire: Excuse me, but it appears a $NUnitCategory result in $enviro is sub-optimal: <https://s3.amazonaws.com/corp-nunitsite/NUnit/appName/$date/TestReport-$enviro-$unique.html|View Results>"
}
else {
PostToSlack ":white_check_mark: The $enviro $NUnitCategory passed. <https://s3.amazonaws.com/corp-nunitsite/NUnit/appName/$date/TestReport-$enviro-$unique.html|View Results>"
}
Remove-Item -Force $reportUnitDir\TestResult.html
Remove-Item -Force $reportUnitDir\TestReport.html
Remove-Item -Force $nUnitDir\TestResult.xml
Remove-Item -Force $reportUnitDir\TestResult.xml
exit $nunitExit
@avironi
Copy link

avironi commented Apr 5, 2019

Seems lots of extra attribute when compared to the vanilla https://library.octopus.com/step-template/actiontemplate-test-run-nunit
Can you please provide only the basic one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment