From a64a0c6f06bd766896c84cbad5559454bbf9b84e Mon Sep 17 00:00:00 2001 From: Thomas Sondergaard Date: Tue, 30 May 2017 17:10:14 +0200 Subject: [PATCH 1/3] Consistent junit reporting regardless of internal SECTIONS Change it so the classname attribute on the element is the test fixture name or "global" regardless of whether the TEST_CASE contains SECTIONs. This way the output is not changed substantially, just because a SECTION is added to a TEST_CASE. --- include/reporters/catch_reporter_junit.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index a671c68f..c8f1238e 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -139,8 +139,7 @@ namespace Catch { std::string className = stats.testInfo.className; if( className.empty() ) { - if( rootSection.childSections.empty() ) - className = "global"; + className = "global"; } writeSection( className, "", rootSection ); } From a6b03031ba56ffda9c2b655ac2d17ed9d49e3659 Mon Sep 17 00:00:00 2001 From: Thomas Sondergaard Date: Tue, 30 May 2017 17:26:46 +0200 Subject: [PATCH 2/3] Use [#filename] tag for junit testcase classname attribute If [#filename] is present in tags, use it for the classname attribute, rather than "global". If the test fixture is present that still takes precedence. --- include/reporters/catch_reporter_junit.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index c8f1238e..2b5a9bd5 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -128,6 +128,13 @@ namespace Catch { xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false ); } + static std::string fileNameTag( const std::set &tags ) { + std::set::const_iterator it = tags.lower_bound("#"); + if( it != tags.end() && !it->empty() && it->front() == '#' ) + return it->substr(1); + return std::string(); + } + void writeTestCase( TestCaseNode const& testCaseNode ) { TestCaseStats const& stats = testCaseNode.value; @@ -139,7 +146,9 @@ namespace Catch { std::string className = stats.testInfo.className; if( className.empty() ) { - className = "global"; + className = fileNameTag(stats.testInfo.tags); + if ( className.empty() ) + className = "global"; } writeSection( className, "", rootSection ); } From 69ff7fcf4243e2b874dda9a8ab34993c31c879f1 Mon Sep 17 00:00:00 2001 From: Thomas Sondergaard Date: Tue, 30 May 2017 21:40:28 +0200 Subject: [PATCH 3/3] Include suite name in junit classname attrib for grouping in jenkins Jenkins groups junit test results by loosely interpreting the classname attribute of the element as a package-qualified java class name such as java.util.String. It ignores the elements in the xml. To organize test results we therefore need to embed the suite name in the classname attribute as if it was a java package name. Fixes #922. --- include/reporters/catch_reporter_junit.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index 2b5a9bd5..5ade59b5 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -150,6 +150,10 @@ namespace Catch { if ( className.empty() ) className = "global"; } + + if ( !m_config->name().empty() ) + className = m_config->name() + "." + className; + writeSection( className, "", rootSection ); }