App page
Requirements and Test Management for Jira
Cloud Server/Data Center
Requirements and Test Management for Jira

Cloud

Server/Data Center

Documentation
FAQ
Release notes
Migration to Cloud
Last updated Dec 27, 2024

JUnit integration

Java (JUnit) #1 example: using the test method name

Test code

In JUnit, you can include the RTM test case key in the test method name or use annotations to add metadata to your tests. In this example, the test method is named test1_TC_KEY_PR_156, where PR-156 is the Test Case issue key. Including the key in the test method name ensures that it appears in the test results, allowing RTM to map the test execution to the corresponding test case.

import org.junit.jupiter.api.Test;

public class ExampleTest {

    @Test
    // example that uses TC_KEY prefix
    public void test1_TC_KEY_PR_156() {
        // Test code here
    }
    
    @Test
    // example with only Test Case issue key
    public void test1_PR_157() {
        // Test code here
    }
}

Test Result File (JUnit XML) After running the tests, JUnit can generate an XML report (TEST-example.xml) that looks like this:

<testsuites id="" name="" tests="1" failures="0" skipped="0" errors="0" time="187.86075">
    <testsuite name="com.deviniti.example.ExampleTest" timestamp="2024-10-03T09:32:45.503Z" hostname="Cloud-Chrome-RTM" tests="1" failures="0" skipped="0" time="24.766" errors="0">
        <testcase name="test1_TC_KEY_PR_156" classname="com.deviniti.example.ExampleTest" time="24.766" />
    </testsuite>
</testsuites>

Java (JUnit) #2 example: printing patterns to console output

Test code

Another way to map tests is to print patterns to console output. Check Mapping tests to Test Cases for details.

import org.junit.jupiter.api.Test;

public class ExampleTest {

    @Test
    public void testSumFunction() {
        // map this test to Test Case by Automation Test Key
        System.out.println("RTM_AUT_TEST_KEY=example.calculator.addFunction");
        // when creating Test Case from test results use summary below
        System.out.println("TC_SUMMARY=\"Calculate the sum of two numbers\"");
        // when creating Test Case from test results link it with requirement by issue key
        System.out.println("REQ_KEY=PR-109");
        
        // Test code here
    }
}

Test Result File (JUnit XML)

After running the tests, JUnit can generate an XML report (TEST-example.xml) that looks like this:

<testcase name="testSumFunction" classname="com.deviniti.example.ExampleTest" time="0.011">
  <system-out><![CDATA[RTM_AUT_TEST_KEY=example.calculator.addFunction
    TC_SUMMARY="Calculate the sum of two numbers"
    REQ_KEY=PR-109
]]></system-out>
</testcase>