A simple and focused REST API testing framework built with REST Assured and JUnit 5 for testing the JSONPlaceholder API.
/posts
- 100 posts/comments
- 500 comments/albums
- 100 albums/photos
- 5000 photos/todos
- 200 todos/users
- 10 users
- β
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
)
- 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
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
- Java 11+ installed
- Maven 3.6+ installed
# 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
@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");
}
@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");
}
}
- HTTP Status Codes - Correct response codes (200, 201, 404)
- Response Structure - Required fields are present and not empty
- Data Types - Fields have correct data types
- Response Time - Reasonable performance (under 5 seconds with warning)
- Object Conversion - JSON can be converted to Java objects
- Business Logic - Data makes sense (e.g., valid email formats, proper IDs)
- 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
β
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
- β Clean, readable test code
- β Clear test names and descriptions
- β Simple assertions with helpful error messages
- β Minimal setup required
- β All 6 JSONPlaceholder endpoints
- β All HTTP methods (GET, POST, PUT, PATCH, DELETE)
- β Query parameter filtering
- β Error handling (404 for non-existent resources)
- β HTTP status code verification
- β Response structure validation
- β Data type checking
- β Performance monitoring
- β Object conversion testing
- β Allure test reports with detailed results
- β Response time tracking
- β Clear test descriptions
- β Request/response logging
# 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
- 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
- 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
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
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
Emmanuel Arhu
Quality Assurance Engineer & Developer
- π Website: emmanuelarhu.link
- πΌ LinkedIn: linkedin.com/in/emmanuelarhu
- π§ Contact: emmanuelarhu.link/contact
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.