Skip to main content

Test Cases Tagging

Test Case ID tagging for automated test cases

Overview

  • The tagged test cases 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 Test Management repository.
  • Test case ID tagging is currently supported only for JUNI-XML based reports.

How to integrate test case ID tagging in Test Management with test suites

Prerequisite

  1. A Project has been created in your BrowserStack Test Management account.
  2. Test cases to be tagged already exist in one or more projects.

Step 1: Add Test Case ID in the test suite

Here is the sample code formats 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)

Step 2: Execute the test suite

Run your test suite with either of the ways to export the results to Test Management:

  1. CI/CD
  2. CLI based

Step 3: Generated Reports

Here is the sample generated report formats:

<?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






Thank you for your valuable feedback

Is this page helping you?

Yes
No

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!

Talk to an Expert
Download Copy