Skip to content

Test case ID

Vadzim Hushchanskou edited this page Sep 2, 2020 · 11 revisions

Test case ID

Test case ID is a parameter that uniquely defines a test in the Report Portal. In java client it is implemented using @TestCaseId annotation.

It contains value and parametrized fields:

  String value() default "";
  boolean parametrized() default false;

Field value of type String allows to explicitly provide Test case ID for a test method/case.

  @TestCaseId("TNG.1.0.1")
  @Test
  public void simpleTest() {
    ...
  }

In case when a test method is a parametrized one, parametrized field can be set to true and one or more of the method parameters can be marked by Test case id Key. In that case only marked parameters will be used for Test Case ID generation and other parameters will be ignored.

  @TestCaseId(parametrized = true)
  @Test(dataProvider = "numbersProvider")
  public void parametrizedTestWithKey(@TestCaseIdKey String testCaseId, Integer expected, Integer evaluated) {
    ...
  } 

In case when a Test case ID is not provided by user it will be generated automatically. Algorithm of Test case ID auto-generation based on a test method codeRef(location in a code) and test method arguments.

For example, with arguments - testCaseId="ID123", expected=2, evaluated=2:

  //result: testCaseId="ID123"
  @TestCaseId(parametrized = true)
  @Test(dataProvider = "numbersProvider")
  public void parametrizedTestWithKey(@TestCaseIdKey String testCaseId, Integer expected, Integer evaluated) {
    ...
  } 

  //result: testCaseId="com.epam.reportportal.example.testng.logback.annotated.TestCaseIdTest.parametrizedTestWithKey[ID123, 2, 2]"
  @Test(dataProvider = "numbersProvider")
  public void parametrizedTestWithKey(String testCaseId, Integer expected, Integer evaluated) {
    ...
  }

  //result: testCaseId="My Test Case ID[ID123, 2, 2]"
  @TestCaseId("My Test Case ID", parametrized = true)
  @Test(dataProvider = "numbersProvider")
  public void parametrizedTestWithKey(String testCaseId, Integer expected, Integer evaluated) {
    ...
  } 

  //result: testCaseId="My Test Case ID[ID123]"
  @TestCaseId("My Test Case ID", parametrized = true)
  @Test(dataProvider = "numbersProvider")
  public void parametrizedTestWithKey(@TestCaseIdKey String testCaseId, Integer expected, Integer evaluated) {
    ...
  } 

Evaluated Test case ID is set as testCaseId field in a request body:

   {
     ...
     "testCaseId":"providedId"
     ...
   }

TestCaseId contains explicit/generated value and will be displayed in the Report Portal, testCaseHash will be generated on server side based on testCaseId and used in business logic operations (history view) to improve performance.