junit and classname/name inconsistency with sections
If I have a test case without sections, the junit output writes differently than if it does have sections
Example showing first a test case with sections (last section entry shown) and second a test case with no sections
<testcase classname="SimpleStringTest::testAssign" name="ConstCharAssignIsNull" time="0.000023"/>
<testcase classname="global" name="SimpleStringTest::testCStr" time="0.000023"/>
Would you consider the second form becoming
<testcase classname="SimpleStringTest::testCStr" name="global" time="0.000023"/>
This maintains consistency of test case names and avoids having lots of simple testcases all being grouped under a single classname "global"
ie generally classname= testcase name, name = section name or some default where no section exists [and perhaps replacing "global" with "default" or "" in name field]
I just ran into this issue as well, and it took me about 3 hours to figure out that there's nothing wrong with my unit test or my Jenkins configuration where I saw the result.
I had added a new unit test by copy+pasting a previous unit test .cpp file, and then changing the names & tags in the TEST_CASE macro and modifying the contents of the test. Intuitively I would have thought a difference like this would come from my TEST_CASE macro, but these were nearly identical, so I had to hunt through includes and see if any #defines were affecting it, etc. It was very obscure that it is affected by the presence of sections. Sample from my output:
<testcase classname="TestSuite.DitherShader.TemporalPatternTest" name="Every value in the temporal pattern is unique" time="0.000104"/>
<testcase classname="global" name="TestSuite.NewShader.TestWithReferenceRasterizer" time="2.174213"/>
I can't reproduce the difference being based on sections:
xarn@Martin-X250:/mnt/c/temp/Catch :) cat 486.cpp
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("No sections", "[none]") {
REQUIRE(1 != 2);
REQUIRE(1 != 3);
}
TEST_CASE("Sections", "[section]") {
SECTION("A") {
REQUIRE(1 != 2);
}
SECTION("B") {
REQUIRE(1 != 3);
}
}
xarn@Martin-X250:/mnt/c/temp/Catch :) clang++ --std=c++11 486.cpp && ./a.out -r junit
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="a.out" errors="0" failures="0" tests="4" hostname="tbd" time="0.00028" timestamp="2019-10-28T14:59:58Z">
<testcase classname="a.out.global" name="No sections" time="0.000105"/>
<testcase classname="a.out.global" name="Sections/A" time="0.000005"/>
<testcase classname="a.out.global" name="Sections/B" time="0.000004"/>
<system-out/>
<system-err/>
</testsuite>
</testsuites>
but the classname does indeed change when you use fixtures:
xarn@Martin-X250:/mnt/c/temp/Catch :) cat 486-fixtures.cpp
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
class TestClass {
std::string s = std::string("hello");
public:
void testCase() {
REQUIRE( s == "hello" );
}
};
struct Fixture {
Fixture() : m_a( 1 ) {}
int m_a;
};
METHOD_AS_TEST_CASE( TestClass::testCase, "A METHOD_AS_TEST_CASE based test run that succeeds", "[class]" )
TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that succeeds", "[class]" ) {
REQUIRE( m_a == 1 );
}
TEST_CASE("No sections", "[none]") {
REQUIRE(1 != 2);
REQUIRE(1 != 3);
}
TEST_CASE("Sections", "[section]") {
SECTION("A") {
REQUIRE(1 != 2);
}
SECTION("B") {
REQUIRE(1 != 3);
}
}
xarn@Martin-X250:/mnt/c/temp/Catch :) clang++ --std=c++11 486-fixtures.cpp && ./a.out -r junit
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="a.out" errors="0" failures="0" tests="6" hostname="tbd" time="0.000561" timestamp="2019-10-28T15:01:25Z">
<testcase classname="a.out.TestClass" name="A METHOD_AS_TEST_CASE based test run that succeeds" time="0.000118"/>
<testcase classname="a.out.Fixture" name="A TEST_CASE_METHOD based test run that succeeds" time="0.000061"/>
<testcase classname="a.out.global" name="No sections" time="0.000038"/>
<testcase classname="a.out.global" name="Sections/A" time="0.00001"/>
<testcase classname="a.out.global" name="Sections/B" time="0.000012"/>
<system-out/>
<system-err/>
</testsuite>
</testsuites>
which to me seems like it is working as intended.