Content ITV PRO
This is Itvedant Content department
Learning Outcome
3
Set up a Rest Assured project using Java and required dependencies.
2
Understand what Rest Assured is and why it is widely used for automating REST APIs.
1
Understand the role of API automation in modern software testing.
Recall
What is API Testing?
Think about a package delivery service.
When an order is placed:
In API communication:
In software testing:
Applications communicate with each other using APIs.
Instead of manually checking these communications, testers create automation scripts.
Rest Assured works like the automation assistant — it automatically sends API requests, checks responses, and ensures everything works as expected
Why API Automation is Important??
Since APIs operate behind the UI, testing them early helps identify issues before they affect the user interface.
Benefits of API automation include:
Faster execution compared to manual testing
Early detection of defects in the backend layer
Easy integration with CI/CD pipelines
Ability to test large numbers of API scenarios repeatedly
Transition to concept
In the previous section, we understood what API testing is and why it is important.
Postman or Swagger help us manually send requests and validate responses
Manual testing can become time-consuming
In real-world projects, APIs need to be tested frequently, repeatedly, and often as part of automated pipelines.
Transition to Concept
This is where API automation tools become essential.
| Manual API Testing | Automation API Testing |
|---|---|
| Performed using tools like Postman or Swagger | Uses automation tools and frameworks |
| Requires manual execution of requests | Tests run automatically with scripts |
| Suitable for quick validation and exploration | Ideal for regression testing and large test suites |
| Not efficient for repetitive testing | Supports continuous integration and continuous testing |
What is REST Assured?
REST Assured is a Java-based API automation testing framework designed specifically for testing RESTful APIs
Built on top of Java HTTP clients like Apache HttpClient, it integrates with popular testing frameworks
What is REST Assured?
Why use REST Assured?
2. BDD-Style Syntax: Write tests that read like natural language specifications
4. CI/CD Integration: Seamlessly works with continuous integration pipelines
3. Method Chaining: Create readable test flows with intuitive method chains.
Maven Project Setup
1. Prepare Tools
2. Create Project
Open IDE and create a new Maven project
3. Configure Details
Set Group ID and Artifact ID for your project
4. Structure Folders
Organize with src/main/java and src/test/java
folders.
Add Dependencies in pom.xml
io.rest-assured
rest-assured
5.3.0
test
org.testng
testng
7.8.0
testAdd these dependencies to your pom.xml file inside the dependencies block. Always use the latest stable versions from Maven Central
Build and Validate Project
Save pom.xml
Verify Libraries
Check External/Referenced Libraries in your IDE.
Run Sample Test
import static io.restassured.RestAssured.*;
import org.testng.annotations.Test;
public class SampleTest {
@Test
public void testStatusCode() {
get("https://jsonplaceholder.typicode.com/posts/1")
.then()
.statusCode(200);
}
}Choosing between TestNG and JUnit
| TestNG Benefits | JUnit Benefits |
|---|---|
| Parallel test execution for faster feedback | Widely adopted in open-source projects |
| Advanced listeners for custom reporting | Simple, lightweight architecture |
| Test grouping for better organization | Excellent IDE integration |
| Dependency management between tests | Familiar to most Java developers |
Both frameworks are fully supported by REST Assured.
Choose based on your project's specific requirements.
Recommended Project Structure
This structure ensures clean, maintainable test architecture as your project grows.
/src
/main
/java (Utility Classes)
/test
/java
/tests
- SampleTest.java
/base
- BaseTest.java
/utils
- JsonUtil.java
- ConfigReader.javaContains actual test classes with API verifications.
Helper classes for JSON parsing and token generation
Shared setup and configuration classes.
Best Practices for Setup
1. Base Configuration
Keep base URI and common headers in a shared base class. This centralizes common settings.
2. Environment Properties
Use properties files for environment-specific configs. Enables easy switching between test environments.
3. Modular Design
Summary
4
Rest Assured automates API testing, ensure reliable backend functionality.
3
Manual testing suits quick checks;automation excels ,large-scale testing.
2
API automation speeds testing,catches issues early, supports continuous testing.
1
API testing validates system communication via requests, responses, and data.
Quiz
Which of the following is a benefit of API automation?
A. Slower execution
B. Requires more manual effort
C. Faster and repeatable testing
D. Only used for UI testing
Quiz-answer
Which of the following is a benefit of API automation?
A. Slower execution
B. Requires more manual effort
C. Faster and repeatable testing
D. Only used for UI testing
By Content ITV