Closed davidwallis closed 7 years ago
@davidwallis3101 If you're looking for a summary of the test results would this work for you?
# Run OVF tests
$tests = Get-OperationValidation -ModuleName '<YourOVFModule>'
$results = $tests | Invoke-OperationValidation
# Create summary of test results
$resultTypes = $results | Group-Object -Property Result
$summary = @{
Passed = ($resultTypes | Where Name -eq 'Passed').Count
Failed = ($resultTypes | Where Name -eq 'Failed').Count
Skipped = ($resultTypes | Where Name -eq 'Skipped').Count
Pending = ($resultTypes | Where Name -eq 'Pending').Count
Total = ($resultTypes | Measure-Object -Property Count -Sum).Sum
}
Thanks, that helped - I have managed to replicate what I had previously using just pester - so I'm good to go using this now 👍
if anyone is interested this is the powershell to invoke my tests with params and format the output:
# Define Params for calling OVF with
$ovfParams = @{
ServerName = "MyServer";
Credentials = (get-credential);
PatchingGroup="A_NewServer"
}
# Run OVF tests
$tests = Get-OperationValidation -ModuleName 'ServerBuildValidation'
$results = $tests | Invoke-OperationValidation -Overrides $ovfParams
# Create summary of test results
$resultTypes = $results | Group-Object -Property Result
$summary = @{
Passed = ($resultTypes | Where-Object Name -eq 'Passed').Count
Failed = ($resultTypes | Where-Object Name -eq 'Failed').Count
Skipped = ($resultTypes | Where-Object Name -eq 'Skipped').Count
Inconclusive = ($resultTypes | Where-Object Name -eq 'Inconclusive').Count
Pending = ($resultTypes | Where-Object Name -eq 'Pending').Count
Total = ($resultTypes | Measure-Object -Property Count -Sum).Sum
}
# Format cells where the value is greater than 0
$params = @{ ScriptBlock = {$args[0] -gt 0} }
# Produce a summary table
$summaryTable = $summary | Select-Object `
@{Name="Passed Count";Expression={$_.Passed}},
@{Name="Failed Count";Expression={$_.Failed}},
@{Name="Skipped Count";Expression={$_.Skipped}},
@{Name="Pending Count";Expression={$_.Pending}},
@{Name="Inconclusive Count";Expression={$_.Inconclusive}},
@{Name="Total Count";Expression={$_.Total}} | New-HtmlTable |
Add-HTMLTableColor -Argument "Failed" -Column "Failed Count" -AttrValue "background-color:#ffb3b3;" @params |
Add-HTMLTableColor -Argument "Passed" -Column "Passed Count" -AttrValue "background-color:#c6ffb3;" @params |
Add-HTMLTableColor -Argument "Skipped" -Column "Skipped Count" -AttrValue "background-color:#9f5fb3;" @params |
Add-HTMLTableColor -Argument "Inconclusive" -Column "Inconclusive Count" -AttrValue "background-color:#5c73b3;" @params
#Compose the html adding the necessary headers
$HTML = New-HTMLHead
$HTML += "<h3>Post Build Test Summary</h3>"
$HTML += $summaryTable
$HTML += "<h3>Post Build Test Results</h3>"
# Create a seperate table for each describe block
foreach ($section in ($results | Select-Object -ExpandProperty RawResult | Select-Object Describe -Unique)) {
# Add a title based on the descibe block name
$HTML += ("<h4>{0}</h4>" -f $section.Describe)
# Get the pester test results
$rawResults = $results | Select-Object -ExpandProperty RawResult | Where-Object -FilterScript { $_.Describe -eq $section.Describe }
# Create a table with the specified columns and apply colouring to the result column
$HTML += $rawResults | Select-Object Context, Name, Result, FailureMessage |
New-HtmlTable |
Add-HTMLTableColor -Argument "Failed" -Column "Result" -AttrValue "background-color:#ffb3b3;" |
Add-HTMLTableColor -Argument "Passed" -Column "Result" -AttrValue "background-color:#c6ffb3;" |
Add-HTMLTableColor -Argument "Skipped" -Column "Result" -AttrValue "background-color:#9f5fb3;" |
Add-HTMLTableColor -Argument "Inconclusive" -Column "Result" -AttrValue "background-color:#5c73b3;"
}
$html = Close-HTML $html
#test it out
set-content C:\users\davidw\documents\test.html $HTML
& 'C:\Program Files\Internet Explorer\iexplore.exe' C:\users\davidw\documents\test.html
And outputs something like this (obviously these aren't my actual tests!!)
Thanks
David
I'm just looking into using this framework to help with packaging up pester tests into modules (obviously!)
One thing I currently do is with pester is output the results using https://github.com/RamblingCookieMonster/PSHTMLTable
you can see in the readme.md I submitted an example for formatting pester output.
I can probably parse rawoutput to get the test results (just working on this) but I don't see the test counts - is it feasable to get this information or support something like passthru?