Test Case ID Tagging
{: .intro} Test Case ID tagging for automated test cases
The tagged test case results are recorded in the test run of Test Management whenever the automation suite is run. These test cases can be both manual or automated type in the Test Management repository.
Integrate test case ID tagging with test suites
Prerequisite
Ensure you have a project and some test cases created in your Test Management account.
Add Test Case ID in the test suite
You can add a test case ID to your test suite with Reporter.log("[[PROPERTY|id=<test-case-id>]]\n", true);
in TestNG and record_property("id", "<test-case-id>")
in PyTest.
Following are the sample code snippets to add test case ID in the test suites.
package com.browserstack;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;
public class BStackDemoTest {
@Test
public void testUpdateUserEmail() {
Reporter.log("[[PROPERTY|id=TC-1]]\n", true);
// [..]
}
@Test
public void addToCart() {
Reporter.log("[[PROPERTY|id=TC-2]]\n", true);
// [..]
}
}
import pytest
def test_div_zero_exception(record_property):
"""
pytest.raises can assert that exceptions are raised (catching them)
"""
with pytest.raises(ZeroDivisionError):
record_property("id", "TC-52628")
x = 1 / 0
def test_keyerror_details(record_property):
"""
The raised exception can be referenced, and further inspected (or asserted)
"""
record_property("id", "TC-52629")
my_map = {"foo": "bar"}
with pytest.raises(KeyError) as ke:
baz = my_map["baz"]
# Our KeyError should reference the missing key, "baz"
assert "baz" in str(ke)
def test_approximate_matches(record_property):
"""
pytest.approx can be used to assert "approximate" numerical equality
(compare to "assertAlmostEqual" in unittest.TestCase)
"""
record_property("id", "TC-52630")
assert 0.1 + 0.2 == pytest.approx(0.3)
Execute the test suite
Run your test suite using one of the following.
- CI/CD pipeline using Azure DevOps or Jenkins.
- CLI.
Reports
Following are the sample test run reports.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by org.testng.reporters.JUnitReportReporter -->
<testsuite hostname="Sh*****" failures="0" tests="2" name="com.browserstack.BStackDemoTest" time="0.006" errors="0" timestamp="2023-04-20T10:46:28 IST" skipped="0">
<testcase classname="com.browserstack.BStackDemoTest" name="testUpdateUserEmail" time="0.000" />
<system-out><![CDATA[[[PROPERTY|id=TC-1]]]]></system-out>
<testcase classname="com.browserstack.BStackDemoTest" name="addToCart" time="0.006" />
<system-out><![CDATA[[[PROPERTY|id=TC-2]]]]></system-out>
</testsuite>
<!-- com.browserstack.BStackDemoTest -->
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="pytest" errors="0" failures="0" skipped="0" tests="7" time="0.017" timestamp="2023-04-18T18:10:07.535667" hostname="Sh*****">
<testcase classname="00_empty_test" name="test_empty" time="0.000" />
<testcase classname="01_basic_test" name="test_example" time="0.000" />
<testcase classname="02_special_assertions_test" name="test_div_zero_exception" time="0.000">
<properties>
<property name="id" value="TC-52628" />
</properties>
</testcase>
<testcase classname="02_special_assertions_test" name="test_keyerror_details" time="0.000">
<properties>
<property name="id" value="TC-52629" />
</properties>
</testcase>
<testcase classname="02_special_assertions_test" name="test_approximate_matches" time="0.000">
<properties>
<property name="id" value="TC-52630" />
</properties>
</testcase>
<testcase classname="03_simple_fixture_test" name="test_with_local_fixture" time="0.000" />
<testcase classname="03_simple_fixture_test" name="test_with_global_fixture" time="0.000" />
</testsuite>
</testsuites>
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!