Last Updated On
This tutorial explains the steps to create a GitHub Action for the Java Rest API tests and execute the tests in that workflow.
Table of Contents
Why GitHub?
GitHub serves as a collaborative platform that supports version control, code collaboration, automated testing, and issue tracking, all of which are crucial elements in the software testing process. It promotes transparency, collaboration, and efficiency in the development and testing workflows.
CI/CD pipelines have contributed to the success of the DevOps cycle in all software development projects. This is a holistic process that bridges development and operations. Continuous integration helps development teams deploy code efficiently, and continuous delivery automates code deployment.
Implementation Steps
Step 1 – Create GitHub Actions and Workflows
I have a repository available in GitHub – RestAssured_TestNG_Demo as shown in the below image. Go to the “Actions” tab. Click on the “Actions” tab.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-122.png?w=1200)
Step 2 – Select the type of Actions
You will see that GitHub recommends Actions depending on the project. In our case, it is recommending actions suitable for a Java project. I have selected the “Java with Maven” option as my project is built in Maven.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-123.png?w=1200)
Step 3 – Generation of Sample pipeline
If you choose an existing option, it will automatically generate a .yaml for the project as shown below.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-124.png?w=1020)
We will replace the current workflow with the following yml file as shown below:
name: Rest API Tests using Rest Assured with TestNG
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Test Execution
run: mvn clean test
- name: Test Report Generation
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: TestNG Report # Name of the folder
path: target/surefire-reports/ # Path to test results
Step 4 – Commit the changes
After the changes, hit the “Start Commit” button.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-113.png?w=580)
This will give the option to add a description for the commit. It will also enable the user to commit either to the main branch or commit to any other branch that exists in the project. Click on the “Commit new file” button to set up the workflow file.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-114.png?w=480)
It will create a maven.yml file as shown below in the project.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-125.png?w=1200)
Step 5 – Verify that the workflow is running
Next, head over to the “Actions” tab, and you will see your YAML workflow file present under the tab. The yellow sign represents that the job is in the queue.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-126.png?w=1200)
In Progress – When the job starts building and running, you will see the status change from “Queued” to “in progress”.
Passed – If the build is successful, you will see a green tick mark.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-119.png?w=1200)
Below is the execution log.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-127.png?w=852)
Click on the workflow and the below screen is displayed. It shows the status of the run of the workflow, the total time taken to run the workflow, and the name of the .yml file.
Below shows all the steps of the workflow.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-130.png?w=1200)
Step 6 – Published TestNG Report on GitHub
From the logs of the Workflow, you can see that the Test Report step was executed successfully.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-129.png?w=1040)
Once the pipeline run, a TestNG Report folder will be generated as shown in the below image:
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-132.png?w=1200)
When we click on the folder TestNG Report, a zipped file will be downloaded, and we can extract it to see all the files contained within it.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-133.png?w=357)
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-134.png?w=693)
Below is the image of emailable-report.html.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-135.png?w=1200)
Below is the image of index.html.
![](https://qaautomation.expert/wp-content/uploads/2023/12/image-136.png?w=1045)
The complete code can be found here on GitHub – vibssingh/RestAssured_TestNG_Demo.
Congratulations! We just created our CI workflow for running our Rest API test cases.