Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. JUnit 5: @DisplayName gives a way to specify generic information in the test name instead of the hard rule based Java method names. This can be used to specify an existing AIO Case Key.
    For example, @DisplayName("SCRUM-TC-1973 : Test forest gets created.")

  2. Testcase key in Underscores : Since Java and Python, do not allow hyphens in their method signatures, AIO Tests allows case keys with underscores as valid mapping. The AIO Test key can be used in the method name by replacing the hyphen with underscores. eg. if AT-TC-123 is being automated by a test, the test method can be named as verifyNotNullType_AT_TC_123 and the results of this method will be marked against AT-TC-123.

  3. Automation Key: The mapping of an AIO Case to an automated JUnit case can happen through a field Automation Key, which can be specified in the Case in AIO Tests app as shown below. The automation key is the fully qualified name of the test method i.e packagename.classname.methodname.
    (info) This can be useful at places where you do not want to add AIO case keys in the name or annotations or where automation is happening first without a manual case being created in AIO Tests.

  4. New Case creation: If no case key (e.g. SCRUM-TC-xx) or automation key is found with existing cases, a new case is created with
    - title as the name value from <testcase> tag of the JUnit report
    - automation key as classname.name from the JUnit report.
    - status as Published
    - automation status as Automated
    - automation owner as user uploading the results

    The following flow summarizes the logic of JUnit case mapping when a key is not found via @DisplayName and via Automation key

    Image Removed


    Image Added

Examples

Below are few examples that show results on testing the ForestCreator.java class.

...

Output: On import of the above report in AIO Tests, the automation key with com.aio.tests.junit4.ForestCreatorTests.plantTree_should_returnNumberOfTrees would be searched for and the cases marked with this key would be added to cycle and updated

Parametrized Named Cases

...

🖊 Add case key as part of the Source and use it in the @ParameterizedTest name value

...

titleJUnit 5 Parametrized Test

...

Convention

With the release of the data driven feature, it is now possible to create cases with datasets from JUnit cases.

The convention for creating data parameters with names is (params: parameterName1={0}, parameterName2={1}, parameterName1={2})

eg.

(params: userType={0},profile={1},income={2}). This example would create a case with 3 data parameters : userType, profile and income and create datasets based on the Junit source values

The below example would create a testcase with 5 datasets and a data parameter named month

Expand
titleJUnit 5
Code Block
@ParameterizedTest(name="(params: month={0})")
@EnumSource(value=Month.class, names = {"APRIL", "JUNE", "SEPTEMBER", "NOVEMBER", "FEBRUARY"},
        mode = EnumSource.Mode.INCLUDE) 
void getValueForAMonth_IsAlwaysBetweenOneAndTwelve(Month month) {
    int monthNumber = month.getValue();
    Assertions.assertTrue(true, "Tree successfully planted"monthNumber >= 1 && monthNumber <= 9);
}

Expand
titleJUnit 4

...

Code Block

...

@Parameterized.Parameters(name="(params : numberA={0},numberB={1})")
public static Collection<Object[]> data() {
    Object[][] 

...

obj = new Object[2][3];

...

    Random r = new Random();
    for (int i = 0; i < 2; i++) {

...

 

...

 

...

      Integer[] insert = {r.nextInt(10), r.nextInt(10), r.nextInt(20)};
        obj[i] = 

...

insert;
 

...

 

...

 

...

 }

...


    return Arrays.asList(obj);
}

@Test
public void test_addTwoNumbers() {
    

...

assertEquals(calculator.add(numberA, numberB), expected);
}

🖊 A new flag has been introduced updateDatassets. This flag controls, whether the change in datasets should be used to update the Junit datasets case or not. The value can be set to false, when a subset of datasets are being run to avoid removal of datasets. If set to true, this flag affects only existing datasets cases.

Parametrized Non-Named Cases

🖊 If the name is not specified, and a default report is generated, AIO Tests generates new parameter names for JUnit 5 reports, which elaborate on user data. However, in Junit 4, in the absence of data in the report, cases would continue to work as individual cases.

In below case, AIO Tests would create a parameter named Parameter 1 and would create 5 datasets with the numbers [1, 3, 5, -3 and 15] as values.

Expand
titleJUnit 5 Default report sample
Code Block
<testcase name="isOdd_ShouldReturnTrueForOddNumbers(int)[1] 1" classname="com.
aio.tests
aiodemos.junit5.
ForestCreatorTests
DataDrivenTests" time="0.
001
0"/>
</testcase>
  <testcase name="
Plant Palm - Case: SCRUM-TC-1622
isOdd_ShouldReturnTrueForOddNumbers(int)[2] 3" classname="com.
aio
aiodemos.
tests.
junit5.
ForestCreatorTests
DataDrivenTests" time="0.001"/>
 
</testcase>
 <testcase name="
Plant Banyan - Case: SCRUM-TC-1633
isOdd_ShouldReturnTrueForOddNumbers(int)[3] 5" classname="com.
aio
aiodemos.
tests.
junit5.
ForestCreatorTests
DataDrivenTests" time="0.001
"> </testcase>

Output : On import of the above report in AIO Tests, the 3 data driving the case would update 3 cases with the keys found in the name, in above case

Parametrized Non-Named Cases

...

"/>
  <testcase name="isOdd_ShouldReturnTrueForOddNumbers(int)[4] -3" classname="com.aiodemos.junit5.DataDrivenTests" time="0.001"/>
  <testcase name="isOdd_ShouldReturnTrueForOddNumbers(int)[5] 15" classname="com.aiodemos.junit5.DataDrivenTests" time="0.0"/>
Code Block
@RunWith(Parameterized.class)
public class ParametrizedRunTest {

  @Parameterized.Parameters
  public static Iterable<Object[]> planTrees() {
      return Arrays.asList(new Object[][] {
              { "Baobab" }, 
              { "Rainbow Eucalyptus" },
              { "Banyan" }
      });
  }
  
Report:  
<testcase name="plantTree[0]" classname="com.aio.tests.ParametrizedRunNonNamedTest" time="0"/>
<testcase name="plantTree[1]" classname="com.aio.tests.ParametrizedRunNonNamedTest" time="0">
    <failure message="asdf" type="org.junit.ComparisonFailure"><![CDATA[org.junit.ComparisonFailure: expected:<[BaobabTree]> but was:<[Rainbow Eucalyptus]>
   at com.aio.tests.ParametrizedRunNonNamedTest.plantTree(ParametrizedRunNonNamedTest.java:33)
]]></failure>
</testcase>
<testcase name="plantTree[2]" classname="com.aio.tests.ParametrizedRunNonNamedTest" time="0"/>

...