Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NUnit3 XML-reports #2208

Merged
merged 22 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ if ($Clean) {
if (-not $LockedRestore) {
dotnet restore "$PSScriptRoot/src/csharp/Pester.sln"
}
else {
else {
dotnet restore "$PSScriptRoot/src/csharp/Pester.sln" --locked-mode
}
dotnet build "$PSScriptRoot/src/csharp/Pester.sln" --no-restore --configuration Release -p:VersionPrefix="$($manifest.ModuleVersion)" -p:VersionSuffix="$($manifest.PrivateData.PSData.Prerelease)"
if (0 -ne $LASTEXITCODE) {
throw "build failed!"
throw 'build failed!'
}
}

Expand All @@ -96,6 +96,7 @@ function Copy-Content ($Content) {

$content = @(
, ("$PSScriptRoot/src/en-US/*.txt", "$PSScriptRoot/bin/en-US/")
, ("$PSScriptRoot/src/schemas/NUnit3/*.xsd", "$PSScriptRoot/bin/schemas/NUnit3/")
, ("$PSScriptRoot/src/nunit_schema_2.5.xsd", "$PSScriptRoot/bin/")
, ("$PSScriptRoot/src/junit_schema_4.xsd", "$PSScriptRoot/bin/")
, ("$PSScriptRoot/src/report.dtd", "$PSScriptRoot/bin/")
Expand Down
2 changes: 1 addition & 1 deletion src/Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $script:SafeCommands['Set-DynamicParameterVariable'] = $ExecutionContext.Session
'New-PesterConfiguration'

# export
'Export-NunitReport'
'Export-NUnitReport'
'ConvertTo-NUnitReport'
'Export-JUnitReport'
'ConvertTo-JUnitReport'
Expand Down
2 changes: 1 addition & 1 deletion src/Pester.RSpec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function New-PesterConfiguration {
Enabled: Enable TestResult.
Default value: $false

OutputFormat: Format to use for test result report. Possible values: NUnitXml, NUnit2.5 or JUnitXml
OutputFormat: Format to use for test result report. Possible values: NUnitXml, NUnit2.5, NUnit3 or JUnitXml
Default value: 'NUnitXml'

OutputPath: Path relative to the current directory where test result report is saved.
Expand Down
9 changes: 6 additions & 3 deletions src/Pester.Runtime.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,18 @@ function New-ParametrizedBlock {
[String[]] $Tag = @(),
[HashTable] $FrameworkData = @{ },
[Switch] $Focus,
[String] $Id,
[Switch] $Skip,
$Data
)

# using the position of Describe/Context as Id to group data-generated blocks. Should be unique enough because it only needs to be unique for the current block, so the way to break this would be to inline multiple blocks with ForEach, but that is unlikely to happen. When it happens just use StartLine:StartPosition
# TODO: Id is used by NUnit2.5 and 3 testresults to group. A better way to solve this?
$id = $StartLine

fflaten marked this conversation as resolved.
Show resolved Hide resolved
foreach ($d in @($Data)) {
# shallow clone to give every block it's own copy
$fmwData = $FrameworkData.Clone()
New-Block -Name $Name -ScriptBlock $ScriptBlock -StartLine $StartLine -Tag $Tag -FrameworkData $fmwData -Focus:$Focus -Skip:$Skip -Data $d
New-Block -Id $id -Name $Name -ScriptBlock $ScriptBlock -StartLine $StartLine -Tag $Tag -FrameworkData $fmwData -Focus:$Focus -Skip:$Skip -Data $d
}
}

Expand Down Expand Up @@ -2597,7 +2600,7 @@ function New-ParametrizedTest () {
)

# using the position of It as Id for the the test so we can join multiple testcases together, this should be unique enough because it only needs to be unique for the current block, so the way to break this would be to inline multiple tests, but that is unlikely to happen. When it happens just use StartLine:StartPosition
# TODO: I don't think the Id is needed anymore
# TODO: Id is used by NUnit2.5 and 3 testresults to group. A better way to solve this?
$id = $StartLine
foreach ($d in $Data) {
New-Test -Id $id -Name $Name -Tag $Tag -ScriptBlock $ScriptBlock -StartLine $StartLine -Data $d -Focus:$Focus -Skip:$Skip
Expand Down
2 changes: 1 addition & 1 deletion src/csharp/Pester/TestResultConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static TestResultConfiguration ShallowClone(TestResultConfiguration confi
public TestResultConfiguration() : base("TestResult configuration.")
{
Enabled = new BoolOption("Enable TestResult.", false);
OutputFormat = new StringOption("Format to use for test result report. Possible values: NUnitXml, NUnit2.5 or JUnitXml", "NUnitXml");
OutputFormat = new StringOption("Format to use for test result report. Possible values: NUnitXml, NUnit2.5, NUnit3 or JUnitXml", "NUnitXml");
OutputPath = new StringOption("Path relative to the current directory where test result report is saved.", "testResults.xml");
OutputEncoding = new StringOption("Encoding of the output file.", "UTF8");
TestSuiteName = new StringOption("Set the name assigned to the root 'test-suite' element.", "Pester");
Expand Down