diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-07-29 17:37:58 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-08-05 14:12:25 +0000 |
commit | 999de9e33e131cc5ad7e1e0befa3421e23d17adf (patch) | |
tree | 93c9b52e31d600d55703de920e7b657629f8a6b5 /src/testlib | |
parent | 3c60333595faa6a47c8ef39e26bc5e5af9d19f26 (diff) |
testlib: Report skipped tests in JUnit reporter as <skipped> elements
The Apache Ant and Surefire Maven specs document a <skipped> element that
can be used to signify skipped test, with a corresponding total skipped
test attribute on the <testsuite>.
The element includes an optional message attribute, documented in the
Surefire spec, and in the Ant source code, but not yet documented in
the reverse-engineered Ant spec:
https://github.com/windyroad/JUnit-Schema/pull/11
Task-number: QTBUG-95424
Change-Id: Ib6417a41b9c328836f4017e6ebf7f7e9cd91288d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit fb16a66b71250f83a9249a0a04064f56d70c9fd3)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qjunittestlogger.cpp | 12 | ||||
-rw-r--r-- | src/testlib/qtestcoreelement_p.h | 3 | ||||
-rw-r--r-- | src/testlib/qtestelementattribute.cpp | 3 | ||||
-rw-r--r-- | src/testlib/qtestelementattribute_p.h | 4 |
4 files changed, 18 insertions, 4 deletions
diff --git a/src/testlib/qjunittestlogger.cpp b/src/testlib/qjunittestlogger.cpp index eb4dc4dee8..a120171c3a 100644 --- a/src/testlib/qjunittestlogger.cpp +++ b/src/testlib/qjunittestlogger.cpp @@ -139,6 +139,9 @@ void QJUnitTestLogger::stopLogging() qsnprintf(buf, sizeof(buf), "%i", errorCounter); currentTestSuite->addAttribute(QTest::AI_Errors, buf); + qsnprintf(buf, sizeof(buf), "%i", QTestLog::skipCount()); + currentTestSuite->addAttribute(QTest::AI_Skipped, buf); + currentTestSuite->addAttribute(QTest::AI_Time, toSecondsFormat(QTestLog::msecsTotalTime()).constData()); @@ -273,6 +276,13 @@ void QJUnitTestLogger::addMessage(MessageTypes type, const QString &message, con Q_UNUSED(file); Q_UNUSED(line); + if (type == QAbstractTestLogger::Skip) { + auto skippedElement = new QTestElement(QTest::LET_Skipped); + skippedElement->addAttribute(QTest::AI_Message, message.toUtf8().constData()); + currentLogElement->addLogElement(skippedElement); + return; + } + auto messageElement = new QTestElement(QTest::LET_Message); auto systemLogElement = systemOutputElement; const char *typeBuf = nullptr; @@ -300,7 +310,7 @@ void QJUnitTestLogger::addMessage(MessageTypes type, const QString &message, con typeBuf = "qfatal"; break; case QAbstractTestLogger::Skip: - typeBuf = "skip"; + Q_UNREACHABLE(); break; case QAbstractTestLogger::Info: typeBuf = "info"; diff --git a/src/testlib/qtestcoreelement_p.h b/src/testlib/qtestcoreelement_p.h index 98de54ccff..458792a738 100644 --- a/src/testlib/qtestcoreelement_p.h +++ b/src/testlib/qtestcoreelement_p.h @@ -141,7 +141,8 @@ const char *QTestCoreElement<ElementType>::elementName() const "benchmark", "message", "system-err", - "system-out" + "system-out", + "skipped" }; if (type != QTest::LET_Undefined) diff --git a/src/testlib/qtestelementattribute.cpp b/src/testlib/qtestelementattribute.cpp index d091804f8c..8609de6d18 100644 --- a/src/testlib/qtestelementattribute.cpp +++ b/src/testlib/qtestelementattribute.cpp @@ -145,7 +145,8 @@ const char *QTestElementAttribute::name() const "time", "timestamp", "hostname", - "classname" + "classname", + "skipped" }; if (attributeIndex != QTest::AI_Undefined) diff --git a/src/testlib/qtestelementattribute_p.h b/src/testlib/qtestelementattribute_p.h index 762ac13430..6c49bda588 100644 --- a/src/testlib/qtestelementattribute_p.h +++ b/src/testlib/qtestelementattribute_p.h @@ -81,6 +81,7 @@ namespace QTest { AI_Timestamp = 17, AI_Hostname = 18, AI_Classname = 19, + AI_Skipped = 20 }; enum LogElementType @@ -95,7 +96,8 @@ namespace QTest { LET_Benchmark = 6, LET_Message = 7, LET_SystemError = 8, - LET_SystemOutput = 9 + LET_SystemOutput = 9, + LET_Skipped = 10 }; } |