Skip to content

Commit

Permalink
Adds inconclusive and skipped tests to nunit report 'ts' files
Browse files Browse the repository at this point in the history
  • Loading branch information
csandfeld committed Feb 3, 2024
1 parent 9ba12d5 commit a21a550
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 3 deletions.
98 changes: 98 additions & 0 deletions tst/Pester.RSpec.TestResults.NUnit25.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,51 @@ i -PassThru:$PassThru {

}

t "should write a skipped test result" {
$sb = {
Describe "Mocked Describe 1" {
It "Skipped testcase" -Skip {
}
}
Describe "Mocked Describe 2" {
It "Skipped testcase" {
Set-ItResult -Skipped
}
}
}
$r = Invoke-Pester -Configuration ([PesterConfiguration]@{ Run = @{ ScriptBlock = $sb; PassThru = $true }; Output = @{ Verbosity = 'None' } })

$xmlResult = $r | ConvertTo-NUnitReport
$xmlTestSuite = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-suite'
$xmlTestCase1 = $xmlTestSuite.results.'test-case'[0]
$xmlTestCase2 = $xmlTestSuite.results.'test-case'[1]

$xmlTestCase1.name | Verify-Equal "Mocked Describe 1.Skipped testcase"
$xmlTestCase1.result | Verify-Equal "Ignored"
$xmlTestCase1.time | Verify-XmlTime $r.Containers[0].Blocks[0].Tests[0].Duration

$xmlTestCase2.name | Verify-Equal "Mocked Describe 2.Skipped testcase"
$xmlTestCase2.result | Verify-Equal "Ignored"
$xmlTestCase2.time | Verify-XmlTime $r.Containers[0].Blocks[1].Tests[0].Duration
}

t "should write an inconclusive test result" {
$sb = {
Describe "Mocked Describe" {
It "Inconclusive testcase" {
Set-ItResult -Inconclusive
}
}
}
$r = Invoke-Pester -Configuration ([PesterConfiguration]@{ Run = @{ ScriptBlock = $sb; PassThru = $true }; Output = @{ Verbosity = 'None' } })

$xmlResult = $r | ConvertTo-NUnitReport
$xmlTestCase = $xmlResult.'test-results'.'test-suite'.'results'.'test-suite'.'results'.'test-suite'.'results'.'test-case'
$xmlTestCase.name | Verify-Equal "Mocked Describe.Inconclusive testcase"
$xmlTestCase.result | Verify-Equal "Inconclusive"
$xmlTestCase.time | Verify-XmlTime $r.Containers[0].Blocks[0].Tests[0].Duration
}

t "should write the test summary" {
$sb = {
Describe "Mocked Describe" {
Expand All @@ -162,6 +207,59 @@ i -PassThru:$PassThru {
$xmlTestResult.time | Verify-Equal (Get-Date -Format "HH:mm:ss" $r.ExecutedAt)
}

t "should write inconclusive count" {
$sb = {
Describe "Mocked Describe" {
It "Inconclusive testcase" {
Set-ItResult -Inconclusive
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport
$xmlResult.'test-results'.inconclusive | Verify-Equal 1

$sb = {
Describe "Mocked Describe" {
It "Inconclusive testcase 1" {
Set-ItResult -Inconclusive
}
It "Inconclusive testcase 2" {
Set-ItResult -Inconclusive
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport
$xmlResult.'test-results'.inconclusive | Verify-Equal 2
}

t "should write skipped count" {
$sb = {
Describe "Mocked Describe" {
It "Skipped testcase" {
Set-ItResult -Skipped
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport
$xmlResult.'test-results'.skipped | Verify-Equal 1

$sb = {
Describe "Mocked Describe" {
It "Skipped testcase 1" -Skip {
}
It "Skippde testcase 2" {
Set-ItResult -Skipped
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport
$xmlResult.'test-results'.skipped | Verify-Equal 2
}

t "should write the test-suite information" {
$sb = {
Describe "Mocked Describe" {
Expand Down
113 changes: 110 additions & 3 deletions tst/Pester.RSpec.TestResults.NUnit3.ts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,60 @@ i -PassThru:$PassThru {

}

t 'should write a skipped test result' {
$sb = {
Describe 'Describe 1' {
It 'Skipped testcase' -Skip {
}
}
Describe 'Describe 2' {
It 'Skipped testcase' {
Set-ItResult -Skipped
}
}
}
$r = Invoke-Pester -Configuration ([PesterConfiguration]@{ Run = @{ ScriptBlock = $sb; PassThru = $true }; Output = @{ Verbosity = 'None' } })

$xmlResult = $r | ConvertTo-NUnitReport -Format NUnit3
$xmlTestSuite = $xmlResult.'test-run'.'test-suite'.'test-suite'
$xmlTestCase1 = $xmlTestSuite.'test-case'[0]
$xmlTestCase2 = $xmlTestSuite.'test-case'[1]

$xmlTestCase1.name | Verify-Equal 'Describe 1.Skipped testcase'
$xmlTestCase1.methodname | Verify-Equal 'Skipped testcase'
$xmlTestCase1.classname | Verify-Equal 'Describe 1'
$xmlTestCase1.fullname | Verify-Equal 'Describe 1.Skipped testcase'
$xmlTestCase1.result | Verify-Equal 'Skipped'
$xmlTestCase1.duration | Verify-XmlTime $r.Containers[0].Blocks[0].Tests[0].Duration

$xmlTestCase2.name | Verify-Equal 'Describe 2.Skipped testcase'
$xmlTestCase2.methodname | Verify-Equal 'Skipped testcase'
$xmlTestCase2.classname | Verify-Equal 'Describe 2'
$xmlTestCase2.fullname | Verify-Equal 'Describe 2.Skipped testcase'
$xmlTestCase2.result | Verify-Equal 'Skipped'
$xmlTestCase2.duration | Verify-XmlTime $r.Containers[0].Blocks[1].Tests[0].Duration
}

t 'should write an inconclusive test result' {
$sb = {
Describe 'Describe' {
It 'Inconclusive testcase' {
Set-ItResult -Inconclusive
}
}
}
$r = Invoke-Pester -Configuration ([PesterConfiguration]@{ Run = @{ ScriptBlock = $sb; PassThru = $true }; Output = @{ Verbosity = 'None' } })

$xmlResult = $r | ConvertTo-NUnitReport -Format NUnit3
$xmlTestCase = $xmlResult.'test-run'.'test-suite'.'test-suite'.'test-case'
$xmlTestCase.name | Verify-Equal 'Describe.Inconclusive testcase'
$xmlTestCase.methodname | Verify-Equal 'Inconclusive testcase'
$xmlTestCase.classname | Verify-Equal 'Describe'
$xmlTestCase.fullname | Verify-Equal 'Describe.Inconclusive testcase'
$xmlTestCase.result | Verify-Equal 'Inconclusive'
$xmlTestCase.duration | Verify-XmlTime $r.Containers[0].Blocks[0].Tests[0].Duration
}

t 'should write the test summary' {
$sb = {
Describe 'Describe' {
Expand All @@ -167,6 +221,59 @@ i -PassThru:$PassThru {
$xmlTestResult.'end-time' | Verify-Equal (($r.ExecutedAt + $r.Duration).ToUniversalTime().ToString('o'))
}

t "should write inconclusive count" {
$sb = {
Describe "Mocked Describe" {
It "Inconclusive testcase" {
Set-ItResult -Inconclusive
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport -Format NUnit3
$xmlResult.'test-run'.inconclusive | Verify-Equal 1

$sb = {
Describe "Mocked Describe" {
It "Inconclusive testcase 1" {
Set-ItResult -Inconclusive
}
It "Inconclusive testcase 2" {
Set-ItResult -Inconclusive
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport -Format NUnit3
$xmlResult.'test-run'.inconclusive | Verify-Equal 2
}

t "should write skipped count" {
$sb = {
Describe "Mocked Describe" {
It "Skipped testcase" {
Set-ItResult -Skipped
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport -Format NUnit3
$xmlResult.'test-run'.skipped | Verify-Equal 1

$sb = {
Describe "Mocked Describe" {
It "Skipped testcase 1" -Skip {
}
It "Skippde testcase 2" {
Set-ItResult -Skipped
}
}
}
$r = invoke-pester -container ( new-pestercontainer -ScriptBlock $sb) -passThru -Output Detailed
$xmlResult = $r | ConvertTo-NUnitReport -Format NUnit3
$xmlResult.'test-run'.skipped | Verify-Equal 2
}

t 'should write the test-suite information' {
$sb = {
Describe 'Describe' {
Expand Down Expand Up @@ -317,7 +424,7 @@ i -PassThru:$PassThru {
t 'should add tags as Category-properties to blocks and tests' {
$sb = {
Describe 'Describe' -Tag 'abc' {
It 'Successful testcase' -Tag 'hello','world' {
It 'Successful testcase' -Tag 'hello', 'world' {
$true | Should -Be $true
}
}
Expand Down Expand Up @@ -524,7 +631,7 @@ i -PassThru:$PassThru {
# behavior based on NUnit3 runner
$sb = {
Describe 'Describe' {
It 'Testcase <_>' -Tag 'hello','world' -ForEach @(1,2) {
It 'Testcase <_>' -Tag 'hello', 'world' -ForEach @(1, 2) {
$true | Should -Be $true
}
}
Expand Down Expand Up @@ -681,7 +788,7 @@ i -PassThru:$PassThru {
t 'should add tags as Category-properties on child test-suites only' {
# behavior based on NUnit3 runner
$sb = {
Describe 'Describe <_>' -Tag 'abc' -ForEach @(1,2) {
Describe 'Describe <_>' -Tag 'abc' -ForEach @(1, 2) {
It 'Testcase' {
$true | Should -Be $true
}
Expand Down

0 comments on commit a21a550

Please sign in to comment.