• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A complete API Test Architecture example using Java and RestAssured providing a real-world example and continuous delivery ready.

Rest-Assured Complete Basic Example

Actions Status

Don't forget to give this project a ⭐

This project was created to start the initial steps with test automation for a REST API using Rest-Assured. It tests the API: combined-credit-api

⚠️ Disclaimer

This project has an educational objective and does not have the best practices that could be applied

Some practices will help you to improve your test architecture, but the central point of this repository and demonstrate an example of running tests for API in a pipeline some practices will help you to improve your test architecture, but the central point of this repository and demonstrate an example of running tests for API in a pipeline

Required software

  • Java JDK 17+
  • Maven installed and in your classpath
  • Clone/download the backend API combined-credit-api

How to execute the tests

You can open each test class on src\test\java and execute all of them, but I recommend you run it by the command line. It enables us to run in different test execution strategies and, also in a pipeline, that is the repo purpose.

Running the backend API

Please, before executing any tests, run the backend API. After cloning this project:

  1. Navigate to the project folder using the Terminal / Command prompt
  2. Execute the following: mvn spring-boot:run
  3. Wait until you see something like this: Application has started! Happy tests!
  4. The API is ready and listen to all requests on http://localhost:8088

Running the test suites

The test suites can be run directly by your IDE or by command line. If you run mvn test all the tests will execute because it's the regular Maven lifecycle to run all the tests.

To run different suites based on the groups defined for each test you must inform the property -Dgroups and the group names. The example below shows how to run the test for each pipeline stage:

pipeline stage command
health check tests mvn test -Dgroups="health"
contract tests mvn test -Dgroups="contract"
functional tests mvn test -Dgroups="functional"
e2e tests mvn test -Dgroups="e2e"

Generating the test report

This project uses Allure Report to automatically generate the test report. There are some configuration to make it happen:

  • aspectj configuration on pom.xml file
  • allure.properties file on src/test/resources

You can use the command line to generate it in two ways:

  • mvn allure:serve: will open the HTML report into the browser
  • mvn allure:report: will generate the HTML port at target/site/allure-maven-plugin folder

About the Project Structure

src/main/java

test

Base Test that sets the initial aspects to make the requests using RestAssured. It also has the configuration to deal with BigDecimal returns and SSL configuration.

client

Classes that do some actions in their endpoints. It's used my the FullSimulationE2ETest to demonstrate and e2e scenario.

commons

It contains a class where will format the URL expected when we create a new resource in the simulation endpoint. You can add any class that can be used in the project.

config

The class Configuration is the connections between the property file api.properties located in src/test/resources/.

The @Config.Sources load the properties file and match the attributes with the @Key, so you automatically have the value. You can see two sources. The first one will get the property values from the system (as environment variables or from the command line) in the case you want to change it, for example, in a pipeline. The second will load the api.properties file from the classpath.

@Config.Sources({
    "system:properties",
    "classpath:api.properties"})

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

data

factory

Test Data Factory classes using java-faker to generate fake data and [Lombok] to create the objects using the Builder pattern.

In a few cases, there are custom data like:

  • the list of existent restrictions and simulations in the database
  • cpf generation
  • data generation returned by the API use
provider

JUnit 5 Arguments to reduce the amount of code and maintenance for the functional tests on SimulationsFunctionalTest

suite

It contains a class having the data related to the test groups.

support

Custom CPF (social security number) generator.

model

Model and Builder class to mapping objects thought serialization and deserialization in use with Rest-Assured.

specs

Request and Response specifications used by the clients and e2e tests. The class InitialStepsSpec set the basePath, baseURI, and port for the custom specs. The classes RestrictionsSpecs and SimulationsSpecs contains the implementation of request and response specifications.

src/test/java

e2e

End-to-End test using both endpoints to simulate the user journey thought the API.

general

Health check test to assure the endpoint is available.

restrictions

Contract and Functional tests to the Restriction endpoint.

simulations

Contract and Functional tests to the Simulations endpoint

src/test/resources

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.

Libraries

Patterns applied

  • Test Data Factory
  • Data Provider
  • Builder
  • Request and Response Specification
  • Base Test

Pipeline

This project uses GitHub Actions to run the all the tests in a pipeline. You can find it at https://github.com/eliasnogueira/restassured-complete-basic-example/blob/master/.github/workflows/test-execution.yml

We have the following pipeline steps:

build -> health check -> contract -> e2d -> funcional 

Except the build, that is the traditional Maven build, the other stages has some parameters to determine the test type and the SUT (System Under Test). The parameters are:

  • -Dgroups: specify which test type will be executed
  • -Dapi.base.uri: specify a new base URI
  • -Dapi.base.path: specify a new base path
  • -Dapi.port: specify a new port
  • -Dapi.health.context: specify a new health context

All the parameters, except the -Dgroups are pointing to Heroku because we can't run it locally. It's a great example about how can you set different attribute values to run your tests.

Do you want to help?

Please read the Contribution guide

More Repositories

1

selenium-java-lean-test-architecture

Ready to use Lean Test Automation Architecture using Java and Selenium WebDriver to speed up your test automation
Java
397
star
2

appium-parallel-execution

A lean, up-to-date, and cross-platform solution to run your mobile tests into a Selenium Grid using Appium.
Java
92
star
3

public-speaking

List of presentation, workshops, and initiatives
66
star
4

100-tips-testing-java

List of 100 tips for Testing with Java
HTML
34
star
5

selenium-java-browser-factory

Example of the Factory design pattern implementation to create browser instances using Selenium WebDriver
Java
22
star
6

java-e2e-test-example

An complete example of a pipeline focusing on API and UI (mobile and web) tests.
Java
19
star
7

health-check-api

An easy way to execute a health check against your API endpoint
Java
14
star
8

appium-read-qrcode

How to read QR content from an Android app using Appium and Zxing
Java
12
star
9

desafio-selenium

Desafios de Selenium WebDriver
Java
10
star
10

palestra-arquitetura-teste-restassured

Repositório da palestra sobre Arquitetura de Teste com RestAssured
Java
8
star
11

appium-cross-platform-example

Appium Cross Platform example using Java
JavaScript
8
star
12

credit-api

Combined API to simulate a credit request (in a Brazilian way!)
Java
8
star
13

3-design-patters-arch-decisions

Repo for the presentation 3 Design Patterns and Architecture Decisions you must use in your project
Java
7
star
14

tdd-exemplo

Exemplo simples sobre como aplicar TDD com um problema de números romanos
Java
6
star
15

appium-workshop

Workshop para aprender os passos iniciais com o Appium
6
star
16

projeto-teste-api-livro-v1

Projeto para iniciar a automação de testes de API do livro "Testes para uma API com Postman e RestAssured"
5
star
17

exemplo-robotium-calabash

Exemplo de teste em aplicações móveis utilizando Robotium (Android) e Calabash (iOS)
Java
5
star
18

eliasnogueira

You can have additional information about me through my social networks and my public-speaking initiatives.
5
star
19

selenium-dynamic-grid-example

Example project that run multi-browser web test automation in parallel using Selenium Grid and Docker
Java
5
star
20

selenium-parallel-execution

Example how to run Selenium tests with Java and TestNG in parallel using a docker container
Java
4
star
21

testes-android-ponta-a-ponta

PHP
4
star
22

testing-alm

Projeto de integração de ferramentas open source a partir de uma ferramenta de automação de teste
Java
4
star
23

selenium-read-qrcode

How to read QR Code content from a web app using Selenium and Zxing
Java
4
star
24

wiremock-service-virtualization

Service Virtualization example using WireMock standalone with JSON files to map the request and responses and Docker to create a persistent container to enable the long-living service.
Dockerfile
4
star
25

exemplo-appium-android-grid

Exemplo de como executar testes com Appium em diferentes dispositivos em uma grid
Java
4
star
26

manage-testing-data-java

Managing different data approaching for using on tests scripts
Java
4
star
27

postman-collection-automacao-testes-api-v1

Coleção do Postman relacionado aos exercícios do livro Testes para uma API com Postman e RestAssured
4
star
28

credito-api

Projeto alvo dos testes do livro Testes para uma API com Postman e RestAssured
Java
3
star
29

simulacao-credito-api

API de Simulação de Crédito que faz parte do livro Automação de Testes de API com RestAssured
Java
3
star
30

javaone-testing-automation

Java
2
star
31

rest-assured-open-api-generator-talk

Simple example from basic REST Assured tests to a better architecture using the OpenAPI Generator
Java
2
star
32

wiremock-credit-restriction-api

Service virtualisation example for the Simulations API
Dockerfile
2
star
33

example-test-data-builder

How to implement and use Test Data Builder
Java
2
star
34

awesome-restassured

2
star
35

credit-restriction-api

This project was created to start the initial steps with test automation for a REST API using RestAssured.
Java
2
star
36

projeto-automacao-unidavi

Java
2
star
37

automacao-fontend-caipiraagil

Projeto que foi desenvolvido na palestra "Automação de front-end Web com métodos Ágeis"
Java
2
star
38

aula-topicos-avancados-teste

Repositório para a aula de Testes Automatizados de Software do Laboratório de Engenharia de Software IV na Unisinos
JavaScript
1
star
39

css-locator-game

Jogo para aprender alguns dos cssSelectors para utilizar na automação de teste para páginas web
JavaScript
1
star
40

restrictions-test

This is the test project for restrictions API. You can see in the readme file the dependent services and projects to be able to use it.
Java
1
star
41

automacao-mobile-ios-android-tdc2016

Exemplo de Automação de Teste para iOs e Android usando Appium - TDC 2016 Florianopolis
Java
1
star
42

basic-pipeline-project-java-selenium

Java
1
star
43

workshop-selenium-grid

Projeto e documentação para a condução do workshop
1
star
44

appium-android-wear

Exemplo de automação para Android Wear com Appium
Java
1
star
45

workshop-api-rest-frisby-base

Projeto base para a automação de uma API REST
JavaScript
1
star
46

parametrizacao-script-teste

Exemplos de parametrização de dados para scripts de automação de teste
Java
1
star
47

automacao-teste-congressodemobile

Java
1
star
48

simulations-client

This is the client project used in the simulations-test to show how we can modularise a test project.
Java
1
star
49

junit-para-testadores-resolvido

Repositório do curso de JUnit para Testadores
Java
1
star
50

junit-para-testadores

1
star
51

credit-simulator-api

This project was created to start the initial steps with test automation for a REST API using RestAssured.
Java
1
star
52

restrictions-client

This is the client project used in the restrictions-test project to show how we can modularise a test project.
Java
1
star
53

pessoa-backend-api

API REST de Cadastro de Pessoa. Aplicação didática para automação de serviços REST
Java
1
star
54

restricao-credito-api

API de Simulação de Crédito que faz parte do livro Automação de Testes de API com RestAssured
Java
1
star