From a21a5506487797f59651a6ef675deee5a4162f65 Mon Sep 17 00:00:00 2001 From: Christian Sandfeld Date: Sat, 3 Feb 2024 21:14:09 +0000 Subject: [PATCH] Adds inconclusive and skipped tests to nunit report 'ts' files --- tst/Pester.RSpec.TestResults.NUnit25.ts.ps1 | 98 +++++++++++++++++ tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 | 113 +++++++++++++++++++- 2 files changed, 208 insertions(+), 3 deletions(-) diff --git a/tst/Pester.RSpec.TestResults.NUnit25.ts.ps1 b/tst/Pester.RSpec.TestResults.NUnit25.ts.ps1 index 3712bc6ed..8b81d3d7f 100644 --- a/tst/Pester.RSpec.TestResults.NUnit25.ts.ps1 +++ b/tst/Pester.RSpec.TestResults.NUnit25.ts.ps1 @@ -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" { @@ -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" { diff --git a/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 b/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 index e81f147f9..e8715db26 100644 --- a/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 +++ b/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 @@ -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' { @@ -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' { @@ -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 } } @@ -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 } } @@ -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 }