In the previous tutorial, I explained the Integration of the Allure Report with Rest Assured with JUnit4. In this tutorial, I will explain how to Integrate Allure Report with Rest Assured and TestNG.
The below example covers the implementation of Allure Report for Rest API using Rest Assured, TestNG, Java, and Maven.
Pre-Requisite
- Java 11 installed
- Maven installed
- Eclipse or IntelliJ installed
This framework consists of:
- Java 11
- Maven – 3.8.1
- Allure Report – 2.14.0
- Rest Assured – 4.4.0
- Allure Rest Assured – 2.14.0
- Allure TestNG – 2.14.0
- Aspectj – 1.9.6
Implementation Steps
- Update Properties section in Maven pom.xml
- Add Rest Assured, Allure-Rest Assured and Allure-TetNG dependencies in POM.xml
- Update Build Section of pom.xml in Allure Report Project.
- Create the Test Code for the testing of REST API under src/test/java
- Create TestNG.xml for the project
- Run the Tests and Generate Allure Report
Step 1 – Update Properties section in Maven pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<rest-assured.version>4.4.0</rest-assured.version>
<allure.testng.version>2.14.0</allure.testng.version>
<allure.rest-assured.version>2.14.0</allure.rest-assured.version>
<jackson.version>2.12.3</jackson.version>
<json.version>20210307</json.version>
<maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<aspectj.version>1.9.6</aspectj.version>
<maven-surefire-plugin-version>3.0.0-M5</maven-surefire-plugin-version>
</properties>
Step 2 – Add the Allure-Rest Assured dependency
<!--Allure Reporting Dependency-->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-rest-assured</artifactId>
<version>${allure.rest-assured.version}</version>
</dependency>
Add other dependencies like Rest Assured and Allure-TetNG dependencies in POM.xml
<dependencies>
<!-- Allure TestNG Dependency -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>${allure.testng.version}</version>
<scope>test</scope>
</dependency>
<!-- Rest Assured Dependency -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<!-- Jackson Dependency -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- JSON Dependency -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
</dependencies>
Step 3 – Update the Build Section of pom.xml in Allure Report Project
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source> <!--For JAVA 8 use 1.8-->
<target>${maven.compiler.target}</target> <!--For JAVA 8 use 1.8-->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin-version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>TestNG.xml</suiteXmlFile>
</suiteXmlFiles>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Step 4 – Create the Test Code for the testing of REST API under src/test/java
To see our request and response in more detail using Rest Assured, we need to add a line to our Rest Assured tests. This will provide the request and response details in the report.
.filter(new AllureRestAssured())
@Epic("REST API Regression Testing using TestNG")
@Feature("Verify CRUID Operations on Employee module")
public class EmployeeDetailsTest {
String BaseURL = "http://dummy.restapiexample.com/api";
@Test(description = "GET Request Operation")
@Story("GET Request with Valid User")
@Severity(SeverityLevel.NORMAL)
@Description("Test Description : Verify the details of employee of id-2")
public void verifyUser() {
// GIVEN
given()
.filter(new AllureRestAssured())
// WHEN
.when()
.get(BaseURL + "/v1/employee/2")
// THEN
.then()
.statusCode(200)
.statusLine("HTTP/1.1 200 OK")
// To verify booking id at index 2
.body("data.employee_name", equalTo("Garrett Winters"))
.body("message", equalTo("Successfully! Record has been fetched."));
}
@Test(description = "GET Request Operation")
@Story("GET Request with Invalid User")
@Severity(SeverityLevel.NORMAL)
@Description("Test Description : Verify the details of employee of id-99999")
public void verifyInvalidUser() {
// Given
given()
.filter(new AllureRestAssured())
// WHEN
.when()
.get(BaseURL + "/v1/employee/99999")
// THEN
.then()
.statusCode(200)
.statusLine("HTTP/1.1 200 OK")
.body("message", equalTo("Successfully! Record has not been fetched."));
}
@Test(description = "POST Request Operation")
@Story("POST Request")
@Severity(SeverityLevel.NORMAL)
@Description("Test Description : Verify the creation of a new employee")
public void createUser() {
JSONObject data = new JSONObject();
data.put("employee_name", "APITest");
data.put("employee_salary", "99999");
data.put("employee_age", "30");
//GIVEN
given()
.filter(new AllureRestAssured())
.contentType(ContentType.JSON)
.body(data.toString())
// WHEN
.when()
.post(BaseURL + "/v1/create")
// THEN
.then()
.statusCode(200)
.body("data.employee_name", equalTo("APITest"))
.body("message", equalTo("Successfully! Record has been added."));
}
}
Step 5 – Create testng.xml for the project
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="com.example.RestAssuredTestNGAllureReport.EmployeeDetailsTest"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Step 6 – Run the Test and Generate Allure Report
To run the tests, use the below command
mvn clean test
In the below image, we can see that two tests failed and one passed out of three tests.

This will create the allure-results folder with all the test reports. These files will be used to generate the Allure Report.

To create Allure Report, use the below command
allure serve

This will generate the beautiful Allure Test Report as shown below.
Allure Report Dashboard
The overview page hosts several default widgets representing the basic characteristics of your project and test environment.

Categories in Allure Report
The categories tab gives you a way to create custom defect classifications to apply for test results. There are two categories of defects – Product Defects (failed tests) and Test Defects (broken tests).

Suites in Allure Report
On the Suites tab a standard structural representation of executed tests, grouped by suites and classes, can be found.

View test history
Each time you run the report from the command line with the mvn clean test command, a new result JSON file will get added to the allure-results folder. Allure can use those files to include a historical view of your tests. Let’s give that a try.
To get started, run mvn clean test a few times and watch how the number of files in the allure-reports folder grows.
Now go back to view your report. Select Suites from the left nav, select one of your tests and click Retries in the right pane. You should see the history of test runs for that test:

Graphs in Allure Report
Graphs allow you to see different statistics collected from the test data: status breakdown or severity and duration diagrams.

Timeline in Allure Report
Timeline tab visualizes retrospective of tests execution, allure adaptors collect precise timings of tests, and here on this tab, they are arranged accordingly to their sequential or parallel timing structure.

Behaviors of Allure Report
This tab groups test results according to Epic, Feature, and Story tags.


Packages in Allure Report
The packages tab represents a tree-like layout of test results, grouped by different packages.

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!
Any way to convert gatling log to allure report?
LikeLike
I don’t have much expertise on Gatling log. Sorry, I won’t be able to help you right now.
LikeLike