Skip to content

Awvyyy/petstore-api-tests-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Petstore API Tests Java

API test automation project for the public Swagger Petstore API, built with Java, Rest Assured, JUnit 5, Maven and Jackson.

The project demonstrates automated API testing for user, store and pet endpoints, including functional, negative and cleanup scenarios.


Tech Stack

  • Java 17
  • Maven
  • Rest Assured
  • JUnit 5
  • Jackson Databind
  • Maven Surefire Plugin

What This Project Covers

The test suite covers common backend API testing scenarios:

  • Sending GET, POST, PUT and DELETE requests
  • Validating HTTP status codes
  • Validating JSON response bodies
  • Working with path parameters
  • Working with query parameters
  • Creating test data dynamically
  • Cleaning up created test data where possible
  • Testing negative cases and invalid input

Tested API Areas

User API

Covered scenarios:

  • Create a user
  • Get user by username
  • Update an existing user
  • Try to get an unknown user
  • Try to log in without a required password query parameter

Store API

Covered scenarios:

  • Place an order
  • Get order by ID
  • Delete order
  • Get store inventory
  • Try to get an order with an invalid ID

Pet API

Covered scenarios:

  • Add a pet
  • Get pet by ID
  • Delete pet
  • Find pets by status
  • Try to get a pet using a non-numeric ID

Project Structure

src/test/java/com/petstore
├── base
│   └── BaseApiTest.java
├── model
├── tests
│   ├── PetApiTests.java
│   ├── StoreApiTests.java
│   └── UserApiTests.java
└── util

Main parts:

  • base — shared Rest Assured setup
  • model — request/response models
  • tests — API test classes
  • util — test data helpers

Base API Configuration

The tests use the public Swagger Petstore demo API:

https://petstore.swagger.io/v2

Request specification is configured in BaseApiTest with:

  • base URI
  • base path
  • JSON content type
  • request/response logging when validation fails

How to Run Tests

Clone the repository:

git clone https://github.com/Awvyyy/petstore-api-tests-java.git
cd petstore-api-tests-java

Run all tests:

mvn test

Run a specific test class:

mvn test -Dtest=UserApiTests
mvn test -Dtest=StoreApiTests
mvn test -Dtest=PetApiTests

Notes About Test Stability

Swagger Petstore is a public shared demo environment. Because of that:

  • Some data may already exist
  • Other users may change data at the same time
  • Exact data assertions can sometimes be unstable
  • Dynamically generated test data is used to reduce collisions
  • Cleanup is included after create operations where possible

Example Test Scenarios

Create and verify user

  1. Generate a unique user
  2. Send POST /user
  3. Send GET /user/{username}
  4. Verify username, first name and email
  5. Delete the created user

Place and delete order

  1. Generate an order
  2. Send POST /store/order
  3. Send GET /store/order/{orderId}
  4. Send DELETE /store/order/{orderId}
  5. Verify the order is no longer available

Add and delete pet

  1. Generate a pet
  2. Send POST /pet
  3. Send GET /pet/{petId}
  4. Verify pet ID, name and status
  5. Delete the created pet

Report

A short testing report is available in REPORT.md. It describes:

  • Framework choice
  • Tested endpoints
  • Functional scenarios
  • Negative scenarios
  • Stability considerations
  • Observed issues

Author

Mihhail Osipchik

About

API test automation project using Java, Rest Assured, JUnit 5 and Maven.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages