Skip to content

This repo demonstrates solution for the API Testing Assignment using Java REST Assured library to design boilerplate automation framework with logging and reporting capabilities.

License

Notifications You must be signed in to change notification settings

itkhanz/RestAssured-API-Testing-Assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Testing with REST Assured and Java

API Tests

  • This project is a solution for the API Testing assignment and automates API endpoints to validate the response.
  • It uses data-driven testing to derive parameterized tests from JSON test data for both the test scenarios.
  • API response is validated for HTTP Status code, response body, and content type.

Pre-requisites

This project is built and tested with the following dependencies:

  • JAVA JDK 17+ installed and JAVA_HOME set as environment variable
  • MAVEN 3.9.2+ installed and MAVEN_HOME set as environment variable

Tech Stack

  • Java 17 as programming language
  • REST Assured Java DSL for easy testing of REST services
  • TestNG as testing framework to support the test creation and hooks
  • java-faker as the faker data generation strategy
  • Log4j2 as the logging management strategy
  • Owner to minimize the code to handle properties files
  • Lombok to reduce the boilerplate and creating POJOs with builder pattern
  • jackson-databind to parse the JSON test data
  • Allure TestNG TestNG adapter for allure reporting
  • Allure rest-assured Filter for rest-assured http client, that generates attachment for allure.
  • GitHub Actions for running tests via Continuous Integration (CI)
  • GitHub Pages for publishing the allure report via CI
  • Checkstyle to adhere to coding standards for Java

Project Structure

.
└── doc/
    ├── src/
    │   ├── main/
    │   │   └── resources/
    │   │       └── log4j2.xml
    │   └── test/
    │       ├── java/
    │       │   └── com/
    │       │       └── itkhanz/
    │       │           ├── api/
    │       │           │   ├── CitiesApi
    │       │           │   └── StreetsApi
    │       │           ├── config/
    │       │           │   └── owner/
    │       │           │       ├── ConfigFactory
    │       │           │       └── GeneralConfig
    │       │           ├── constants/
    │       │           │   ├── enums/
    │       │           │   │   ├── City
    │       │           │   │   └── StatusCode
    │       │           │   ├── Globals
    │       │           │   └── Route
    │       │           ├── factories/
    │       │           │   ├── FakerFactory
    │       │           │   └── TestDataLoader
    │       │           ├── models/
    │       │           │   └── pojos/
    │       │           │       ├── Cities
    │       │           │       ├── CityStreets
    │       │           │       └── StreetsRoot
    │       │           ├── specs/
    │       │           │   ├── CitiesSpecBuilder
    │       │           │   └── StreetsSpecBuilder
    │       │           ├── tests/
    │       │           │   ├── CitiesTest
    │       │           │   └── StreetsTest
    │       │           └── utils/
    │       │               ├── AssertionUtils
    │       │               └── JacksonUtils
    │       └── resources/
    │           ├── test-data/
    │           │   ├── cities.json
    │           │   └── streets.json
    │           ├── test-suites/
    │           │   └── testng.xml
    │           ├── allure.properties
    │           └── general.properties
    ├── target
    └── pom.xml

Test Scenarios

User story A – Address checks

AS A backend developer

I WANT TO find city and street names for a particular German postcode

SO THAT I can help customers select their address details more easily

Scenario 1: Find the cities for a given postcode

Scenario 2: Find the streets for a given postcode

Running Tests

  • Clone the repo
  • Open the project POM.xml in IDE of your choice and run the maven build that will download and install the required dependencies.
    • IntelliJ IDE is recommended.
  • Use IDE Terminal or navigate to the project root directory and run following command in terminal:
mvn clean test
  • It will run the whole regression suite comprising of 08 test cases split between 2 test classes.
  • Results will be available in terminal after the build is finished.

test results

Test Reporting

  • HTML report is generated by mavens surefire plugin, and is available at target/surefire-reports/index.html

Allure Reports Setup

  • Allure Report requires a web server to view the results. If we directly open the index.html file, we won't see any reports. To install Allure, first download and install Scoop/brew and then install allure using it.

  • Follow the instructions for Allure Report Installation

    • Install via Homebrew (for macOS and Linux)
      • Make sure Homebrew is installed.
    brew install allure
    • Install via Scoop (for Windows)
      • Make sure Scoop is installed.
    scoop install allure
  • allure --version will show the version of allure downloaded and installed

  • Allure HTML report is generated by allure, and is available at target/allure-results/

    • To view the allure report, run the command allure serve target/allure-results which will open the HTML report in your browser.
    • Allure report contains the request and response body as attachment.
      • To populate the request payload, and response body in allure report, we can use the .filter(new AllureRestAssured()) method in our request and response specifications.
    • It also shows the test description, use story, and test steps in the test body.

Before executing the tests again, stop the allure pressing Ctrl + c.

allure report

Continuous Integration CI with GitHub Actions

  • This project has a GitHub Action workflow that triggers REST Assured API tests on each push or pull request to the main branch on Ubuntu VM.
  • It caches the maven dependencies to save the build and run time.
  • It then uploads the allure-results as test artifact and publishes the allure report to GitHub Pages.
  • Published allure report can be found on GitHub Pages site: https://itkhanz.github.io/RestAssured-API-Testing-Assignment/

About

This repo demonstrates solution for the API Testing Assignment using Java REST Assured library to design boilerplate automation framework with logging and reporting capabilities.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages