In our previous article, we talked about integration TestNG based automation test to TestRail. In this tutorial, i am going to tell how to integrate JUnit to your test suite.

Tech Stack

  • Java
  • JUnit

Assumption

We expect you to store the automation test case in TestRail.

Here are our test cases that we keep in TestRail app.

  • Valid Login has 1 as ID
  • Invalid Login has 2 as ID

Create Annotation to Associate Test Code with Test Rails ID

We already covered that part in many articles. You can refer to

  • https://www.swtestacademy.com/integrate-test-automation-results-with-testrail-testng/
  • https://www.swtestacademy.com/custom-java-annotations/

Create a Test Suite in TestRail

Firstly, we need to create a different suite for every execution that we execute so we’ll be able to store the result in different execution records. So we should use BeforeClass annotation and create a Test Suite by using TestRail API’s.  You can download the TestRails Java bindings from this site so you’ll have a base structure to reach TestRails’ API’s.

  • First, we create a Client with our username and password.
  • Then we use add_run API to create a test run. You need to provide the test project Id to the endpoint and parameters. You can check the docs via this link
    • include_all means include all case
    • name will be the name of your test run for specific Test Rails project.
  • After the suite is created properly, we extract the run id from response payload.

Now execute this method and see that Test Run is created.

Retrieve Test Case ID from Annotation

Secondly, we need to update the test case’s status after execution, I need to have the id stated in the annotation before we start the execution. By using the below code, you can get the TestRail annotations related to test and store this value in test context. Now test context has test run id and test case id. Before annotation is useful for this job.