Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Missing timestamp from test suite attributes in junit xml export

Open GitHubEddie opened this issue 2 years ago • 1 comments

Checklist

What is the issue?

The junit_schema_4.xsd contains an optional attribute called timestamp under the testsuite element.

The issue is during a junit result object conversion to XML the timestamp is not included. For example,

<testsuite name="&lt;ScriptBlock&gt;:1" tests="136" errors="0" failures="2" hostname="COMPUTER1" id="0" skipped="0" disabled="0" package="&lt;ScriptBlock&gt;:1" time="2.644" >

The testsuite timestamp attribute is useful for tools like Allure Reports. Without the timestamp attribute the Allure dashboard looks like this ('UNKNOWN' in report title) image

Expected Behavior

The expectation would be for the timestamp attribute to be present on the junit XML.

<testsuite name="&lt;ScriptBlock&gt;:1" tests="136" errors="0" failures="2" hostname="COMPUTER1" id="0" skipped="0" disabled="0" package="&lt;ScriptBlock&gt;:1" time="2.644" timestamp="2023-12-05T21:04:41.4970014Z">

With the timestamp attribute available the Allure Reports Overview returns a title with detail from the test image

Steps To Reproduce

Export-JUnitReport -Result $PesterObject -Path "C:\JUnit_export.xml"

or

ConvertTo-JUnitReport -Result $PesterObject

Describe your environment

Pester version     : 5.5.0 C:\Program Files\WindowsPowerShell\Modules\Pester\5.5.0\Pester.psm1
PowerShell version : 5.1.22621.2506
OS version         : Microsoft Windows NT 10.0.22621.0

Possible Solution?

This should be resolved by adding something like this

$XmlWriter.WriteAttributeString('timestamp', (Get-UTCTimeString $Action.ExecutedAt))

to the Pester.psm1 function Write-JUnitTestSuiteAttributes

GitHubEddie avatar Dec 05 '23 22:12 GitHubEddie

Thanks for the suggestion. Sounds like a good idea, as long as the implementation is compatible with Jenkins and other JUnit report readers. 👍

Based on what I've found it's expected to be local time without timezone information unlike NUnit3. See https://github.com/jest-community/jest-junit/issues/43

Would you like to submit a PR for this?

fflaten avatar Dec 08 '23 13:12 fflaten