summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-29 15:33:20 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-05 16:11:11 +0200
commit73fbc6600ecb56ea7da32deb4118b7f3dc2301f5 (patch)
tree163cc69c46b66f94521c2a990e935e23db6b7244 /src/testlib
parenta961c612937cf9ad1bb7e014cd9372497d88ba40 (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. Task-number: QTBUG-95424 Change-Id: I3097d10c03c2a29709960372301b29055d224e10 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit bb74e72aa92b599cb4c80c23161ce9b66639ec01) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qjunittestlogger.cpp9
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,