Skip to content

emmanuelarhu/jsonplaceholder-api-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

77 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JSONPlaceholder API Testing Framework

A simple and focused REST API testing framework built with REST Assured and JUnit 5 for testing the JSONPlaceholder API.

🎯 What This Framework Tests

6 JSONPlaceholder Resources

  • /posts - 100 posts
  • /comments - 500 comments
  • /albums - 100 albums
  • /photos - 5000 photos
  • /todos - 200 todos
  • /users - 10 users

HTTP Operations Tested

  • βœ… GET /resource - Get all items
  • βœ… GET /resource/1 - Get single item by ID
  • βœ… POST /resource - Create new item
  • βœ… PUT /resource/1 - Update existing item
  • βœ… PATCH /resource/1 - Partially update item
  • βœ… DELETE /resource/1 - Delete item
  • βœ… Query Parameters - Filter resources (e.g., ?postId=1, ?userId=1)

πŸ› οΈ Technology Stack

  • Java 11+
  • Maven - Build management
  • REST Assured 5.3.2 - API testing
  • JUnit 5.10.0 - Test framework
  • Allure 2.24.0 - Test reporting
  • Jackson - JSON processing

πŸ“ Simple Project Structure

jsonplaceholder-api-testing/
β”œβ”€β”€ src/test/java/com/emmanuelarhu/
β”‚   β”œβ”€β”€ base/
β”‚   β”‚   └── BaseTest.java           # Common test setup
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Post.java               # Post model
β”‚   β”‚   β”œβ”€β”€ User.java               # User model  
β”‚   β”‚   β”œβ”€β”€ Comment.java            # Comment model
β”‚   β”‚   β”œβ”€β”€ Album.java              # Album model
β”‚   β”‚   β”œβ”€β”€ Photo.java              # Photo model
β”‚   β”‚   └── Todo.java               # Todo model
β”‚   └── tests/
β”‚       β”œβ”€β”€ PostsTest.java          # Posts API tests
β”‚       β”œβ”€β”€ UsersTest.java          # Users API tests
β”‚       β”œβ”€β”€ CommentsTest.java       # Comments API tests
β”‚       β”œβ”€β”€ AlbumsTest.java         # Albums API tests
β”‚       β”œβ”€β”€ PhotosTest.java         # Photos API tests
β”‚       └── TodosTest.java          # Todos API tests
β”œβ”€β”€ pom.xml                         # Maven configuration
└── README.md                       # This documentation

⚑ Quick Start

1. Prerequisites

  • Java 11+ installed
  • Maven 3.6+ installed

2. Clone and Run

# Clone the repository
git clone <your-repo-url>
cd jsonplaceholder-api-testing

# Run all tests
mvn clean test

# Run specific test class
mvn test -Dtest=PostsTest

# Generate Allure report
mvn allure:serve

πŸ§ͺ Test Examples

Posts API Tests

@Test
@DisplayName("GET /posts - Should return all 100 posts")
public void testGetAllPosts() {
    Response response = getRequest()
        .when()
        .get("/posts")
        .then()
        .statusCode(200)
        .body("$", hasSize(100))
        .body("[0].id", notNullValue())
        .body("[0].title", not(emptyString()))
        .extract().response();
    
    // Verify response time
    verifyResponseTime(response.getTime());
    
    // Convert to objects and verify
    Post[] posts = response.as(Post[].class);
    assertEquals(100, posts.length, "Should have exactly 100 posts");
    
    System.out.println("βœ… Successfully retrieved " + posts.length + " posts");
}

Comments Filtering

@Test
@DisplayName("GET /comments?postId=1 - Should filter comments by post")
public void testFilterCommentsByPost() {
    Response response = getRequest()
        .queryParam("postId", 1)
        .when()
        .get("/comments")
        .then()
        .statusCode(200)
        .body("postId", everyItem(equalTo(1)))
        .extract().response();
    
    Comment[] comments = response.as(Comment[].class);
    for (Comment comment : comments) {
        assertEquals(1, comment.getPostId(), "All comments should belong to post 1");
    }
}

βœ… What Each Test Verifies

For Every Endpoint:

  1. HTTP Status Codes - Correct response codes (200, 201, 404)
  2. Response Structure - Required fields are present and not empty
  3. Data Types - Fields have correct data types
  4. Response Time - Reasonable performance (under 5 seconds with warning)
  5. Object Conversion - JSON can be converted to Java objects
  6. Business Logic - Data makes sense (e.g., valid email formats, proper IDs)

Specific Validations:

  • Posts: Title and body are not empty, userId exists
  • Users: Email contains "@", name and username are not empty
  • Comments: Email format, postId links to valid post
  • Albums: Title exists, userId links to valid user
  • Photos: URLs are not empty, albumId links to valid album
  • Todos: Completion status is boolean, userId links to valid user

πŸ“Š Test Output Examples

βœ… Successfully retrieved 100 posts
βœ… Response time: 245ms
βœ… Successfully retrieved post: Post{id=1, userId=1, title='sunt aut facere...'}
βœ… Successfully retrieved 5 comments for post 1
βœ… Successfully created new post with ID: 101
βœ… Successfully updated post: Post{id=1, userId=1, title='Updated Post Title'}
βœ… Successfully deleted post 1
βœ… Correctly returned 404 for non-existent post

πŸ”§ Key Features

Simple and Focused

  • βœ… Clean, readable test code
  • βœ… Clear test names and descriptions
  • βœ… Simple assertions with helpful error messages
  • βœ… Minimal setup required

Comprehensive Coverage

  • βœ… All 6 JSONPlaceholder endpoints
  • βœ… All HTTP methods (GET, POST, PUT, PATCH, DELETE)
  • βœ… Query parameter filtering
  • βœ… Error handling (404 for non-existent resources)

Built-in Validation

  • βœ… HTTP status code verification
  • βœ… Response structure validation
  • βœ… Data type checking
  • βœ… Performance monitoring
  • βœ… Object conversion testing

Professional Reporting

  • βœ… Allure test reports with detailed results
  • βœ… Response time tracking
  • βœ… Clear test descriptions
  • βœ… Request/response logging

πŸš€ Running Different Test Scenarios

# Run all tests
mvn clean test

# Run specific endpoint tests
mvn test -Dtest=PostsTest
mvn test -Dtest=UsersTest
mvn test -Dtest=CommentsTest

# Run with verbose output
mvn test -X

# Generate and serve Allure report
mvn allure:serve

# Generate static Allure report
mvn allure:report

πŸ“‹ Test Plan Summary

Functional Testing

  • CRUD Operations - Create, Read, Update, Delete for all endpoints
  • Data Validation - Verify response structure and data integrity
  • Filtering - Test query parameters and filtering capabilities
  • Error Handling - Test 404 responses for non-existent resources

Non-Functional Testing

  • Performance - Monitor response times with warnings for slow responses
  • Data Integrity - Verify relationships between resources (e.g., commentsβ†’posts)
  • JSON Processing - Test object serialization/deserialization

πŸ“ˆ Allure Reports

The framework generates comprehensive Allure reports that include:

  • βœ… Test Results Overview - Pass/fail statistics
  • βœ… Test Case Details - Individual test execution details
  • βœ… Request/Response Data - Full HTTP request and response logs
  • βœ… Performance Data - Response time tracking
  • βœ… Error Analysis - Detailed failure information

🎯 Success Criteria

All tests pass when:

  • βœ… Correct number of resources returned (100 posts, 10 users, etc.)
  • βœ… All required fields are present and not empty
  • βœ… HTTP status codes are correct (200, 201, 404)
  • βœ… Response times are under 5 seconds
  • βœ… Data types match expectations
  • βœ… Filtering works correctly
  • βœ… CRUD operations complete successfully

πŸ‘¨β€πŸ’» Author

Emmanuel Arhu
Quality Assurance Engineer & Developer


This framework demonstrates clean, simple API testing practices while providing comprehensive coverage of the JSONPlaceholder API. It's designed to be easy to understand, maintain, and extend.

About

A simple and focused REST API testing framework built with REST Assured and JUnit 5 for testing the JSONPlaceholder API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages