diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-07-29 15:33:20 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-05 03:58:49 +0200 |
commit | bb74e72aa92b599cb4c80c23161ce9b66639ec01 (patch) | |
tree | df41ff4cb03b4000c4c876d95630f9d894c30839 /src/testlib/qjunittestlogger.cpp | |
parent | 973e74399e807fb6f351a7d330c8c8b85b66bc5a (diff) |
testlib: Reduce JUnit test duration reporting to millisecond precision
The original Ant JUnit reporter produced test durations via Double.toString(),
supporting arbitrary precisions, and the de-facto schema declared them
as xs:decimal.
Sadly, the now popular Maven Surefire reporter limited the duration to
millisecond precision, and hard-coded this into its schema as SUREFIRE_TIME:
https://issues.apache.org/jira/browse/SUREFIRE-1533
Unfortunately this definition spread into tools such as the Jenkins xUnit
plugin, which relies on the schema provided by Maven Surefire:
https://issues.jenkins.io/browse/JENKINS-52152
As a result, anything that produces higher precision results will not
validate in the Jenkins xUnit plugin.
Other test frameworks have bitten the bullet and reduced their precision
correspondingly, e.g.:
https://github.com/catchorg/Catch2/issues/2221
https://github.com/catchorg/Catch2/commit/581c46249acf8389e9
We follow suit, and our JUnit XML output now validates against both
the Jenkins JUnit and xUnit plugins, as well as the original Apache
Ant de-facto schema.
Pick-to: 6.2
Task-number: QTBUG-95424
Change-Id: I3097d10c03c2a29709960372301b29055d224e10
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/testlib/qjunittestlogger.cpp')
-rw-r--r-- | src/testlib/qjunittestlogger.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/testlib/qjunittestlogger.cpp b/src/testlib/qjunittestlogger.cpp index a34b431060..cac447e58f 100644 --- a/src/testlib/qjunittestlogger.cpp +++ b/src/testlib/qjunittestlogger.cpp @@ -77,6 +77,11 @@ static qreal elapsedTestCaseSeconds() return elapsedTestcaseTime.nsecsElapsed() / 1e9; } +static QByteArray toSecondsFormat(qreal ms) +{ + return QByteArray::number(ms / 1000, 'f', 3); +} + void QJUnitTestLogger::startLogging() { QAbstractTestLogger::startLogging(); @@ -135,7 +140,7 @@ void QJUnitTestLogger::stopLogging() currentTestSuite->addAttribute(QTest::AI_Errors, buf); currentTestSuite->addAttribute(QTest::AI_Time, - QByteArray::number(QTestLog::msecsTotalTime() / 1000, 'f').constData()); + toSecondsFormat(QTestLog::msecsTotalTime()).constData()); currentTestSuite->addLogElement(listOfTestcases); @@ -205,7 +210,7 @@ void QJUnitTestLogger::leaveTestFunction() void QJUnitTestLogger::leaveTestCase() { currentLogElement->addAttribute(QTest::AI_Time, - QByteArray::number(elapsedTestCaseSeconds(), 'f').constData()); + toSecondsFormat(elapsedTestCaseSeconds()).constData()); } void QJUnitTestLogger::addIncident(IncidentTypes type, const char *description, |