A comprehensive learning platform for API testing using Java, Spring Boot, and RestAssured. This project provides real-world examples, extensive documentation, and step-by-step learning modules to master API testing from basics to advanced concepts.
Get up and running in 5 minutes:
# Copy the environment template
cp env.example .env
# Update the .env file with your values
# DB_USERNAME=sa
# DB_PASSWORD=your_secure_password_here
# H2_CONSOLE_ENABLED=false
# LOG_LEVEL=INFO
# ... (see env.example for all variables)
# Load environment variables
export $(cat .env | xargs) # Linux/Mac# Clone and setup
git clone <repository-url>
cd api-testing-java
mvn clean install
# Run the application
mvn spring-boot:run
# Access the APIs
# API Documentation: http://localhost:8080/api/swagger-ui.html
# Health Check: http://localhost:8080/api/health
# H2 Database: http://localhost:8080/api/h2-console (disabled by default)
# Run tests
mvn test- REST API Testing with RestAssured
- Spring Boot Development and testing
- Database Integration with JPA/Hibernate
- Test Automation and CI/CD practices
- Performance Testing and monitoring
- Layered Architecture: Controllers → Services → Repositories
- RESTful APIs: Standard HTTP methods and status codes
- Data Validation: Input validation and error handling
- Testing Pyramid: Unit → Integration → API tests
- User Management: Full CRUD operations with search
- Product Catalog: Product management with categories
- Health Monitoring: Application health checks
- Advanced Search: Filtering and pagination
- 50+ Test Scenarios: Covering all API endpoints
- RestAssured Framework: Modern API testing
- Test Data Management: Automated data setup/cleanup
- Performance Testing: Response time validation
- Swagger Documentation: Interactive API docs
- Database Console: H2 web interface
- Logging: Structured logging with SLF4J
- Configuration: Environment-based settings
| Technology | Version | Purpose |
|---|---|---|
| Java | 17 | Programming language |
| Spring Boot | 3.2 | Application framework |
| Spring Data JPA | 3.2 | Data persistence |
| H2 Database | 2.2 | In-memory database |
| RestAssured | 5.3 | API testing framework |
| JUnit 5 | 5.9 | Test execution |
| Maven | 3.6+ | Build tool |
| Swagger/OpenAPI | 2.2 | API documentation |
api-testing-java/
├── src/
│ ├── main/java/com/apitester/
│ │ ├── controller/ # REST Controllers
│ │ ├── service/ # Business Logic
│ │ ├── repository/ # Data Access
│ │ ├── model/ # Entity Models
│ │ └── config/ # Configuration
│ ├── main/resources/ # Configuration files
│ └── test/java/com/apitester/
│ └── api/ # API Tests
├── docs/ # 📚 Comprehensive Documentation
├── pom.xml # Maven configuration
└── README.md # This file
# Get all users
GET /api/users
# Create user
POST /api/users
{
"username": "testuser",
"email": "[email protected]",
"firstName": "Test",
"lastName": "User"
}
# Get user by ID
GET /api/users/{id}
# Update user
PUT /api/users/{id}
# Delete user
DELETE /api/users/{id}
# Search users
GET /api/users/search/firstname?firstName=John
GET /api/users/active# Get all products
GET /api/products
# Create product
POST /api/products
{
"name": "Test Product",
"price": 99.99,
"stockQuantity": 10,
"category": "ELECTRONICS"
}
# Get by category
GET /api/products/category/ELECTRONICS
# Price range search
GET /api/products/price/range?minPrice=10&maxPrice=100
# Update stock
PATCH /api/products/{id}/stock?stockQuantity=50# Basic health check
GET /api/health
# Detailed health info
GET /api/health/detailed
# Readiness check
GET /api/health/ready@Test
void testGetAllUsers() {
given()
.contentType(ContentType.JSON)
.when()
.get("/users")
.then()
.statusCode(200)
.body("$", hasSize(greaterThan(0)));
}@Test
void testCreateUser() {
Map<String, Object> userData = new HashMap<>();
userData.put("username", "testuser");
userData.put("email", "[email protected]");
given()
.contentType(ContentType.JSON)
.body(userData)
.when()
.post("/users")
.then()
.statusCode(201)
.body("username", equalTo("testuser"));
}@Test
void testCreateUser_ValidationError() {
Map<String, Object> invalidData = new HashMap<>();
invalidData.put("username", ""); // Invalid: empty username
given()
.contentType(ContentType.JSON)
.body(invalidData)
.when()
.post("/users")
.then()
.statusCode(400)
.body("errors", hasSize(greaterThan(0)));
}- Start Here: Quick Start Guide
- Understand Architecture: Project Overview
- Learn Testing: API Testing Guide
- Practice: Run tests and modify scenarios
- Study Services: Services Explained
- Configuration: Test Configuration
- Add Features: Create new endpoints
- Write Tests: Add comprehensive test coverage
- RestAssured Tutorial: Learn the testing framework
- Test Data Management: Handle test data effectively
- Performance Testing: Load and stress testing
- Test Automation: CI/CD integration
- Main Documentation - Index to all docs
- Quick Start - Get running in 5 minutes
- Project Overview - Architecture and design
- API Testing Guide - Comprehensive testing tutorial
- Services Explained - Business logic layer
- Test Configuration - Testing setup and configuration
- Module 1: Basic Testing - Getting started
- Module 2: Advanced Testing - Complex scenarios
- Module 3: Test Automation - Automation strategies
- Module 4: Performance Testing - Load testing
- ✅ Java 17+ installed
- ✅ Maven 3.6+ installed
- ✅ IDE (IntelliJ IDEA, Eclipse, VS Code)
-
Clone the repository
git clone <repository-url> cd api-testing-java
-
Build the project
mvn clean install
-
Run the application
mvn spring-boot:run
-
Verify the setup
- Open: http://localhost:8080/api/health
- Should return:
{"status":"UP","application":"API Testing Java"}
-
Explore the APIs
- API Documentation: http://localhost:8080/api/swagger-ui.html
- Database Console: http://localhost:8080/api/h2-console
-
Run tests
mvn test
The application comes with pre-loaded sample data:
- John Doe ([email protected]) - Active
- Jane Smith ([email protected]) - Active
- Bob Wilson ([email protected]) - Inactive
- Alice Brown ([email protected]) - Active
- Charlie Davis ([email protected]) - Suspended
- Electronics: MacBook Pro ($2499.99), iPhone 15 Pro ($999.99)
- Clothing: Cotton T-Shirt ($24.99), Slim Fit Jeans ($79.99)
- Books: Clean Code ($44.99), Design Patterns ($54.99)
- Home & Sports: Coffee Maker ($89.99), Yoga Mat ($34.99)
# Start application
mvn spring-boot:run
# Build project
mvn clean install
# Run tests
mvn test
# Package application
mvn package# Run specific test class
mvn test -Dtest=UserApiTest
# Run specific test method
mvn test -Dtest=UserApiTest#testGetAllUsers
# Run with test profile
mvn test -Dspring.profiles.active=test
# Run with debug logging
mvn test -Dlogging.level.com.apitester=DEBUG# Access H2 console (development only)
# Set H2_CONSOLE_ENABLED=true in environment variables
# Open: http://localhost:8080/api/h2-console
# JDBC URL: jdbc:h2:mem:testdb
# Username: sa (or DB_USERNAME value)
# Password: [your configured DB_PASSWORD]- ✅ Run the application
- ✅ Explore API documentation
- ✅ Understand project structure
- ✅ Write basic API tests
- 🔄 Study service layer architecture
- 🔄 Add new API endpoints
- 🔄 Implement business logic
- 🔄 Create custom queries
- 🔄 Write comprehensive test suites
- 🔄 Learn RestAssured advanced features
- 🔄 Implement test data management
- 🔄 Add performance tests
- 🔄 Security testing
- 🔄 Load testing
- 🔄 CI/CD integration
- 🔄 Production deployment
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow Java coding standards
- Add tests for new functionality
- Update documentation for changes
- Ensure all tests pass
-
Port 8080 already in use
lsof -ti:8080 | xargs kill -9
-
Java version issues
java -version # Should be 17+ -
Maven build issues
mvn clean install -U
-
Database connection issues
- Check H2 console accessibility
- Verify JDBC URL and credentials
- 📚 Documentation: Check the docs folder
- 🐛 Issues: Create an issue for bugs
- 💬 Discussions: Use GitHub discussions for questions
- Simple GET requests: < 100ms
- Complex queries: < 500ms
- Create/Update operations: < 200ms
- Concurrent users: 100+ simultaneous requests
- Database connections: Configurable pool
- Memory usage: Optimized for development
- ✅ Password Hashing: BCrypt password encryption
- ✅ Input Validation: Bean Validation on all inputs
- ✅ Security Headers: Comprehensive security headers
- ✅ Environment Variables: Secure configuration management
- ✅ SQL Injection Prevention: JPA/Hibernate protection
- ✅ XSS Prevention: Content-Type and XSS protection headers
- ✅ H2 Console Control: Environment-based console access
- ✅ Logging Security: Configurable log levels
- 🔧 Environment Variables: See
env.examplefor configuration - 🔧 Security Documentation: See
SECURITY.mdfor detailed security info - 🔧 Password Protection: Passwords excluded from API responses
- 🔄 JWT/OAuth authentication
- 🔄 Role-based authorization
- 🔄 API rate limiting
- 🔄 CORS configuration
- 📖 Complete Documentation - All guides and tutorials
- 🎓 API Testing Guide - Comprehensive testing tutorial
- 🛠️ Services Explained - Business logic deep dive
- ⚙️ Test Configuration - Testing setup guide
- 🌟 Star the repository if you find it helpful
- 🔄 Fork and contribute to improve the project
- 💬 Share your experience in discussions
- 🐛 Report issues for bugs or improvements
By using, forking, or modifying this project, you acknowledge and agree that:
- You are solely responsible for the security, configuration, and operation of your instance
- The original creator is not liable for any security breaches, data loss, or damages
- You must implement proper security measures before using in any production environment
- You are responsible for keeping dependencies updated and following security best practices
- This is educational software - use at your own risk
- This project contains sample data and default configurations for learning purposes
- DO NOT use default passwords or configurations in production
- Always change default credentials and implement proper authentication
- Review all security settings before deployment
- This project is not production-ready without additional security hardening
This software is provided "as is" without warranty of any kind. The original creator disclaims all warranties, express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose.
This project is licensed under the MIT License - see the LICENSE file for details.
Important: Please read the DISCLAIMER.md file for important legal disclaimers and user responsibility information.
- Spring Boot Team for the amazing framework
- RestAssured Community for the testing framework
- H2 Database for the in-memory database
- All Contributors who help improve this project
Begin your API testing journey today!
- Quick Start: Follow the 5-minute setup guide
- Learn: Study the comprehensive documentation
- Practice: Run tests and experiment with the APIs
- Build: Add new features and write tests
- Share: Contribute back to the community
Happy Testing! 🧪✨