Skip to content

Commit

Permalink
Use "hostname" attribute when parsing JUnit XML.
Browse files Browse the repository at this point in the history
When reading JUnit XML files, in addition to the "name" and "classname" attributes, also use the "hostname" attribute to differentiate test cases.

Closes #10878.
  • Loading branch information
fniessink committed Feb 24, 2025
1 parent 979ba75 commit 402c32a
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 33 deletions.
9 changes: 6 additions & 3 deletions components/collector/src/source_collectors/junit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def _include_entity(self, entity: Entity) -> bool:
def __entity(case_node: Element, case_result: str) -> Entity:
"""Transform a test case into a test case entity."""
class_name = case_node.get("classname", "")
host_name = case_node.get("hostname", "")
name = case_node.get("name", "unknown")
key = f"{class_name}:{name}"
old_key = name # Key was changed after Quality-time 5.16.1, enable migration of user entity data
return Entity(key=key, old_key=old_key, name=name, class_name=class_name, test_result=case_result)
key = f"{class_name}:{host_name}:{name}"
old_key = f"{class_name}:{name}" # Key was changed after v5.25.0, enable migration of user entity data
return Entity(
key=key, old_key=old_key, name=name, class_name=class_name, host_name=host_name, test_result=case_result
)
8 changes: 4 additions & 4 deletions components/collector/tests/source_collectors/junit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class JUnitCollectorTestCase(SourceCollectorTestCase):
JUNIT_XML = """
<testsuites>
<testsuite name="ts1" timestamp="2009-12-19T17:58:59" failures="1" errors="1" skipped="1" tests="4">
<testcase name="tc1" classname="cn"/>
<testcase name="tc2" classname="cn"><failure/></testcase>
<testcase name="tc3" classname="cn"><error/></testcase>
<testcase name="tc4" classname="cn"><skipped/></testcase>
<testcase name="tc1" classname="cn" hostname="h1" />
<testcase name="tc2" classname="cn" hostname="h1"><failure/></testcase>
<testcase name="tc3" classname="cn" hostname="h2"><error/></testcase>
<testcase name="tc4" classname="cn" hostname="h2"><skipped/></testcase>
</testsuite>
<testsuite name="ts2" timestamp="2009-12-19T17:58:59" failures="0" errors="1" skipped="0" tests="1">
<testcase name="tc5" classname="cn"><error/></testcase>
Expand Down
111 changes: 100 additions & 11 deletions components/collector/tests/source_collectors/junit/test_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,70 @@ def setUp(self):
"""Extend to set up JUnit test data."""
super().setUp()
self.expected_entities = [
{"key": "cn:tc1", "old_key": "tc1", "name": "tc1", "class_name": "cn", "test_result": "passed"},
{"key": "cn:tc2", "old_key": "tc2", "name": "tc2", "class_name": "cn", "test_result": "failed"},
{"key": "cn:tc3", "old_key": "tc3", "name": "tc3", "class_name": "cn", "test_result": "errored"},
{"key": "cn:tc4", "old_key": "tc4", "name": "tc4", "class_name": "cn", "test_result": "skipped"},
{"key": "cn:tc5", "old_key": "tc5", "name": "tc5", "class_name": "cn", "test_result": "errored"},
{"key": "cn:tc6", "old_key": "tc6", "name": "tc6", "class_name": "cn", "test_result": "failed"},
{"key": "cn:tc7", "old_key": "tc7", "name": "tc7", "class_name": "cn", "test_result": "skipped"},
{"key": "cn:tc8", "old_key": "tc8", "name": "tc8", "class_name": "cn", "test_result": "passed"},
{
"key": "cn:h1:tc1",
"old_key": "cn:tc1",
"name": "tc1",
"class_name": "cn",
"host_name": "h1",
"test_result": "passed",
},
{
"key": "cn:h1:tc2",
"old_key": "cn:tc2",
"name": "tc2",
"class_name": "cn",
"host_name": "h1",
"test_result": "failed",
},
{
"key": "cn:h2:tc3",
"old_key": "cn:tc3",
"name": "tc3",
"class_name": "cn",
"host_name": "h2",
"test_result": "errored",
},
{
"key": "cn:h2:tc4",
"old_key": "cn:tc4",
"name": "tc4",
"class_name": "cn",
"host_name": "h2",
"test_result": "skipped",
},
{
"key": "cn::tc5",
"old_key": "cn:tc5",
"name": "tc5",
"class_name": "cn",
"host_name": "",
"test_result": "errored",
},
{
"key": "cn::tc6",
"old_key": "cn:tc6",
"name": "tc6",
"class_name": "cn",
"host_name": "",
"test_result": "failed",
},
{
"key": "cn::tc7",
"old_key": "cn:tc7",
"name": "tc7",
"class_name": "cn",
"host_name": "",
"test_result": "skipped",
},
{
"key": "cn::tc8",
"old_key": "cn:tc8",
"name": "tc8",
"class_name": "cn",
"host_name": "",
"test_result": "passed",
},
]

async def test_tests(self):
Expand All @@ -36,8 +92,22 @@ async def test_failed_tests(self):
value="2",
total="8",
entities=[
{"key": "cn:tc2", "old_key": "tc2", "name": "tc2", "class_name": "cn", "test_result": "failed"},
{"key": "cn:tc6", "old_key": "tc6", "name": "tc6", "class_name": "cn", "test_result": "failed"},
{
"key": "cn:h1:tc2",
"old_key": "cn:tc2",
"name": "tc2",
"class_name": "cn",
"host_name": "h1",
"test_result": "failed",
},
{
"key": "cn::tc6",
"old_key": "cn:tc6",
"name": "tc6",
"class_name": "cn",
"host_name": "",
"test_result": "failed",
},
],
)

Expand All @@ -64,6 +134,18 @@ async def test_repeated_test_case_names(self):
response = await self.collect(get_request_text=junit_xml_repeated_test_case_name)
self.assert_measurement(response, value="4", total="4")

async def test_repeated_test_case_names_and_class_name(self):
"""Test that repeated test case and class names are distinguished."""
junit_xml_repeated_test_case_name_and_class_name = """<testsuites>
<testsuite timestamp="2009-12-19T17:58:59">
<testcase name="tc1" classname="cn1" hostname="host1"/>
<testcase name="tc1" classname="cn1" hostname="host2"/>
<testcase name="tc1" classname="cn2" hostname="host1"/>
<testcase name="tc1" classname="cn2" hostname="host2"/>
</testsuite></testsuites>"""
response = await self.collect(get_request_text=junit_xml_repeated_test_case_name_and_class_name)
self.assert_measurement(response, value="4", total="4")

async def test_one_top_level_nested_test_suite(self):
"""Test that a JUnit XML file with one top level nested test suite works."""
xml = """
Expand All @@ -79,6 +161,13 @@ async def test_one_top_level_nested_test_suite(self):
value="1",
total="1",
entities=[
{"key": "cn:tc1", "old_key": "tc1", "name": "tc1", "class_name": "cn", "test_result": "errored"},
{
"key": "cn::tc1",
"old_key": "cn:tc1",
"name": "tc1",
"class_name": "cn",
"host_name": "",
"test_result": "errored",
},
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
name="test",
attributes=[
EntityAttribute(name="Class name"),
EntityAttribute(name="Host name"),
EntityAttribute(name="Test case", key="name"),
EntityAttribute(name="Test result", color=RESULT_COLORS),
],
Expand Down
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ If your currently installed *Quality-time* version is not the latest version, pl
### Added

- Allow for measuring merge requests using Bitbucket as source. Closes [#10225](https://github.com/ICTU/quality-time/issues/10225).
- When reading JUnit XML files, in addition to the "name" and "classname" attributes, also use the "hostname" attribute to differentiate test cases. Closes [#10878](https://github.com/ICTU/quality-time/issues/10878).

### Fixed

Expand Down
31 changes: 16 additions & 15 deletions docs/src/versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ The table below contains the *Quality-time* releases since the last minor of the

| Version | Date | Mongo | FC | Migrations | Downgrade | Upgrade | Manual changes |
|------------|--------------|--------|--------|------------|-----------------|-----------------|----------------|
| v5.25.0 | 2025-02-14 | v8 | v8 | | v5.20.0-v5.24.0 | n/a | no |
| v5.24.0 | 2025-02-06 | v8 | v8 | | v5.20.0-v5.23.0 | v5.25.0 | no |
| v5.23.0 | 2025-01-27 | v8 | v8 | | v5.20.0-v5.22.0 | v5.24.0-v5.25.0 | no |
| v5.22.0 | 2025-01-16 | v8 | v8 | | v5.20.0-v5.21.0 | v5.23.0-v5.25.0 | no |
| v5.21.0 | 2024-12-12 | v8 | v8 | | v5.20.0 | v5.22.0-v5.25.0 | no |
| v5.20.0 | 2024-12-05 | v8 | **v8** | added | not possible | v5.21.0-v5.25.0 | no |
| v5.19.0 | 2024-11-22 | v8 | v7 | | v5.14.0-v5.18.0 | v5.20.0-v5.25.0 | no |
| v5.18.0 | 2024-11-06 | v8 | v7 | | v5.14.0-v5.17.1 | v5.19.0-v5.25.0 | no |
| v5.17.1 | 2024-10-25 | v8 | v7 | | v5.14.0-v5.17.0 | v5.18.0-v5.25.0 | no |
| v5.17.0 | 2024-10-17 | **v8** | v7 | | v5.14.0-v5.16.2 | v5.17.1-v5.25.0 | no |
| v5.16.2 | 2024-10-03 | v7 | v7 | | v5.14.0-v5.16.1 | v5.17.0-v5.25.0 | no |
| v5.16.1 | 2024-09-26 | v7 | v7 | | v5.14.0-v5.16.0 | v5.16.2-v5.25.0 | no |
| v5.16.0 | 2024-09-19 | v7 | v7 | added | v5.14.0-v5.15.0 | v5.16.1-v5.25.0 | no |
| v5.15.0 | 2024-07-30 | v7 | v7 | | v5.14.0 | v5.16.0-v5.25.0 | no |
| v5.14.0 | 2024-07-05 | v7 | **v7** | added | not possible | v5.15.0-v5.25.0 | no |
| v5.26.0 | [unreleased] | v8 | v8 | added | not possible | n/a | no |
| v5.25.0 | 2025-02-14 | v8 | v8 | | v5.20.0-v5.24.0 | v5.26.0 | no |
| v5.24.0 | 2025-02-06 | v8 | v8 | | v5.20.0-v5.23.0 | v5.25.0-v5.26.0 | no |
| v5.23.0 | 2025-01-27 | v8 | v8 | | v5.20.0-v5.22.0 | v5.24.0-v5.26.0 | no |
| v5.22.0 | 2025-01-16 | v8 | v8 | | v5.20.0-v5.21.0 | v5.23.0-v5.26.0 | no |
| v5.21.0 | 2024-12-12 | v8 | v8 | | v5.20.0 | v5.22.0-v5.26.0 | no |
| v5.20.0 | 2024-12-05 | v8 | **v8** | added | not possible | v5.21.0-v5.26.0 | no |
| v5.19.0 | 2024-11-22 | v8 | v7 | | v5.16.1-v5.18.0 | v5.20.0-v5.26.0 | no |
| v5.18.0 | 2024-11-06 | v8 | v7 | | v5.16.1-v5.17.1 | v5.19.0-v5.26.0 | no |
| v5.17.1 | 2024-10-25 | v8 | v7 | | v5.16.1-v5.17.0 | v5.18.0-v5.26.0 | no |
| v5.17.0 | 2024-10-17 | **v8** | v7 | | v5.16.1-v5.16.2 | v5.17.1-v5.26.0 | no |
| v5.16.2 | 2024-10-03 | v7 | v7 | | v5.16.1 | v5.17.0-v5.26.0 | no |
| v5.16.1 | 2024-09-26 | v7 | v7 | added | not possible | v5.16.2-v5.26.0 | no |
| v5.16.0 | 2024-09-19 | v7 | v7 | added | not possible | v5.16.1-v5.26.0 | no |
| v5.15.0 | 2024-07-30 | v7 | v7 | | v5.14.0 | v5.16.0-v5.26.0 | no |
| v5.14.0 | 2024-07-05 | v7 | **v7** | added | not possible | v5.15.0-v5.26.0 | no |
| v5.13.0 | 2024-05-23 | v7 | v6 | added | not possible | v5.14.0-v5.16.2 | no |
| v5.12.0 | 2024-05-17 | v7 | v6 | added | not possible | v5.13.0-v5.16.2 | no |
| v5.11.0 | 2024-04-22 | v7 | v6 | | v5.6.0-v5.10.0 | v5.12.0-v5.16.2 | no |
Expand Down

0 comments on commit 402c32a

Please sign in to comment.