Skip to content

Commit

Permalink
When measuring test cases with Visual Studio TRX as source, search al…
Browse files Browse the repository at this point in the history
…l test category items for test case ids, instead cutting the search short after the first match.

Fixes #10460.
  • Loading branch information
fniessink committed Dec 9, 2024
1 parent 338432a commit 4b927b4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
5 changes: 3 additions & 2 deletions components/collector/src/metric_collectors/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class TestCases(MetricCollector):
"timeout": "errored",
"warning": "errored",
}
# Regular expression to identify test case ids in entity attributes:
TEST_CASE_KEY_RE = re.compile(r"\w+\-\d+")
# Regular expression to identify test case ids in entity attributes. Matches identifiers of the form BAR-123,
# while ensuring they are not part of longer identifiers such as FOO-BAR-123 or BAR-123-456:
TEST_CASE_KEY_RE = re.compile(r"(?<![-\w])\b[A-Za-z]+\-\d+\b(?![-\w])")
ENTITY_ATTRIBUTES_TO_SEARCH = ("name", "test_name", "description")
# The supported source types for test cases and test reports:
TEST_CASE_SOURCE_TYPES: ClassVar[list[str]] = ["jira"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def _include_entity(self, entity: Entity) -> bool:
def __entity(test: Element, result: str, namespaces: Namespaces) -> Entity:
"""Transform a test case into a test entity."""
name = test.attrib["name"]
for category in test.findall(".//ns:TestCategoryItem", namespaces):
if match := re.search(TestCases.TEST_CASE_KEY_RE, category.attrib["TestCategory"]):
name += f" ({match[0]})"
break
category_items = test.findall(".//ns:TestCategoryItem", namespaces)
categories = [item.attrib["TestCategory"] for item in category_items]
matches = [match[0] for category in categories if (match := re.search(TestCases.TEST_CASE_KEY_RE, category))]
if matches:
name += f" ({', '.join(sorted(matches))})"
key = test.attrib["id"]
return Entity(key=key, name=name, test_result=result)
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ class VisualStudioTRXCollectorTestCase(SourceCollectorTestCase):
<TestDefinitions>
<UnitTest name="BestaandeZaakOpenen" id="446a0829-8d87-1082-ab45-b2ab9f846325">
<TestCategory>
<TestCategoryItem TestCategory="FeatureTag" />
<TestCategoryItem TestCategory="ScenarioTag1" />
<TestCategoryItem TestCategory="JIRA-224" />
<TestCategoryItem TestCategory="This is not an identifier" />
<TestCategoryItem TestCategory="This is not an-identifier-1" />
<TestCategoryItem TestCategory="This is not an identifier-1-2" />
<TestCategoryItem TestCategory="This is -not-3 an identifier" />
<TestCategoryItem TestCategory="This is not-4- an identifier" />
<TestCategoryItem TestCategory="This is 5-not an identifier" />
<TestCategoryItem TestCategory="This is not an identifier 6" />
<TestCategoryItem TestCategory="This is an identifier: JIRA-224" />
<TestCategoryItem TestCategory="JIRA-225 is also an identifier" />
</TestCategory>
<Execution id="daf369f6-7c54-482d-a12c-68357679bd78" />
<TestMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
self.expected_entities = [
{
"key": "446a0829-8d87-1082-ab45-b2ab9f846325",
"name": "BestaandeZaakOpenen (JIRA-224)",
"name": "BestaandeZaakOpenen (JIRA-224, JIRA-225)",
"test_result": "Passed",
},
{
Expand Down
6 changes: 6 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ If your currently installed *Quality-time* version is not the latest version, pl

<!-- The line "## <square-bracket>Unreleased</square-bracket>" is replaced by the release/release.py script with the new release version and release date. -->

## [Unreleased]

### Fixed

- When measuring test cases with Visual Studio TRX as source, search all test category items for test case ids, instead of cutting the search short after the first match. Fixes [#10460](https://github.com/ICTU/quality-time/issues/10460).

## v5.20.0 - 2024-12-05

### Added
Expand Down

0 comments on commit 4b927b4

Please sign in to comment.