From bb74e72aa92b599cb4c80c23161ce9b66639ec01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 29 Jul 2021 15:33:20 +0200 Subject: testlib: Reduce JUnit test duration reporting to millisecond precision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/testlib/qjunittestlogger.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') 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, -- cgit v1.2.3