Skip to content

The NUnit report is invalid when some tests contain ForEach/TestCase data #2143

Open
@rcarpenter79

Description

@rcarpenter79

General summary of the issue

When I mix tests in the same block where some contain data sets in ForEach with other tests that do not, the NUnit report is generated incorrectly and fails the NUnit2.5 schema validation.

Describe your environment

Pester version     : 5.3.1 C:\Program Files\WindowsPowerShell\Modules\Pester\5.3.1\Pester.psm1
PowerShell version : 7.2.1
OS version         : Microsoft Windows NT 10.0.19043.0

Steps to reproduce

I created a simple test that shows this problem.
I'm running this in VSCode.

I downloaded the NUnit2.5 xsd schema file and placed that in the same folder with the report and used Notepad++ with the XML Tools plugin to validate the report structure.

function Test-IsString
{
    param
    (
        [PSObject]
        $Variable
    )

    return $Variable -is [String]
}

$PesterPreference = [PesterConfiguration]::Default
$PesterPreference.Output.Verbosity = 'Detailed'
$PesterPreference.TestResult.Enabled = $true

Push-Location -Path $PSScriptRoot

Describe -Name 'Demonstrate NUnit Problem' -Fixture {
    It 'Should return <Result> when type is <Type>' -ForEach @(
        @{ Type = 'String'; Variable = [String] 'Test'; Result = $true  }
        @{ Type = 'Int';    Variable = [Int] 0;         Result = $false }
        @{ Type = 'Bool';   Variable = [Bool] $true;    Result = $false }
    ) {
        Test-IsString -Variable $Variable | Should -Be $Result
    }

    It 'Should have a One Parameter' {
        (Get-Command Test-IsString).Parameters.Keys.Count | Should -Be 1
    }
}

Pop-Location

Possible Solution? (optional)

A work around is to separate tests in to different Context blocks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions