Missing timestamp from test suite attributes in junit xml export
Checklist
- [X] Issue has a meaningful title
- [X] I have searched the existing issues. See all issues
- [X] I have tested using the latest version of Pester. See Installation and update guide.
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="<ScriptBlock>:1" tests="136" errors="0" failures="2" hostname="COMPUTER1" id="0" skipped="0" disabled="0" package="<ScriptBlock>: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)
Expected Behavior
The expectation would be for the timestamp attribute to be present on the junit XML.
<testsuite name="<ScriptBlock>:1" tests="136" errors="0" failures="2" hostname="COMPUTER1" id="0" skipped="0" disabled="0" package="<ScriptBlock>: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
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
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?