This repository contains the configuration and architecture to create API automated tests using Rest Assured.
The test examples are based on the APIs provided by Reqres.in
- Java JDK 11+
- Maven
- Lombok
- RestAssured library to test REST APIs
- JUnit 5 to support the test creation
- Owner to manage the property files
- java-faker to generate fake data
- Log4J2 as the logging strategy
- Allure Report as the testing report strategy
By default, the tests use the properties values from the QA environment, but it is possible to change that using the property environment
. Check out some possibilities:
run | command |
---|---|
local | mvn test -Denvironment=local |
develop | mvn test -Denvironment=dev |
qa | mvn test -Denvironment=qa |
If you execute mvn test
, all the tests will be executed by default.
To run different groups/test suites, you can use the property -D
, including the group name. Take a look on some examples:
run | command |
---|---|
login tests | mvn -Dgroups="login" test |
user tests | mvn -Dgroups="user" test |
all tests | mvn test |
To automatically generate the test report. You can use the command line to generate it in two ways:
mvn allure:serve
: will open the HTML report into the browsermvn allure:report
: will generate the HTML port at target/site/allure-maven-plugin folder
You can also use the profiles to generate reports from a specific test suite:
run | command |
---|---|
login report | mvn test allure:report -Dgroups="login" |
user report | mvn test allure:report -Dgroups="user" |
all tests report | mvn test allure:report |
The HTML report is generated in the following path: target > site > allure-maven-plugin > index.html
.
Notice that it is possible to select an environment, a group and generate a report with a unique command:
mvn test allure:report -Denvironment=dev -Dgroups="user"
Base Test that sets the initial settings to execute requests using RestAssured.
It contains any class that is used in the entire project. For example, it has the HeadersDefinition class that that contains the headers configuration used in all the test requests.
The class Configuration
loads the property files located in src/test/resources/conf
, based on the environment selected for the test run.
@LoadPolicy(LoadType.MERGE)
@Config.Sources({"classpath:conf/${environment}.properties"})
public interface Configuration extends Config{
...
}
The environment variable is read on the ConfiguratorManager
.
This class reduces the amount of code necessary to get any information on the properties file.
This strategy uses Owner library
Test Data Factory classes using java-faker to generate fake data and [Lombok] to create the objects using the Builder pattern.
JUnit 5 Arguments to reduce the amount of code and maintenance for the functional tests on SimulationsFunctionalTest
It contains a class having the data related to the test groups.
Includes classes to generate data part of pre-conditions for some test cases
Model and Builder class to map objects thought serialization and deserialization in use with Rest-Assured.
It has a schemas
folder with the JSON Schemas to enable Contract Testing using Rest-Assured. Also, the properties file to easily configure the API URI.