VOOZH about

URL: https://www.geeksforgeeks.org/springboot/how-to-test-spring-boot-project-using-zerocode/

⇱ How to Test Spring Boot Project using ZeroCode? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Test Spring Boot Project using ZeroCode?

Last Updated : 16 Mar, 2026

ZeroCode is an automated testing framework used to test REST APIs in Spring Boot applications. It allows developers to write API test scenarios in JSON format and execute them automatically.

  • Used for automated REST API testing.
  • Test cases are written in JSON scenarios instead of Java code.
  • Helps validate API request, response, and status codes.

Supported Testing Types

The ZeroCode framework supports multiple types of automated testing for modern applications.

  • REST: Enables automated testing of RESTful APIs by sending HTTP requests and validating responses.
  • SOAP: Allows testing of SOAP-based web services and their XML responses.
  • Security: Helps validate authentication, authorization, and secure API interactions.
  • Load/Stress: Supports performance testing to check how APIs behave under heavy traffic.
  • Database: Enables verification of database operations such as inserts, updates, and queries.
  • Apache Kafka: Allows testing of message-based systems and Kafka event streams.
  • GraphQL: Supports testing of GraphQL APIs by validating queries and responses.

Steps for Implementation

Step 1: Create Spring Boot Maven Project

Create a Spring Boot Maven project that will contain the REST API and testing setup.

  • Use Spring Initializr to create the project.
  • Add Spring Boot Web dependency for REST APIs.
  • Import the project into IDE.

Project Structure:

👁 Project Structure
 

Add the ZeroCode dependency in the pom.xml file.

pom.xml

Step 3: Create Model Class

Create a model class GeekUser.java that represents the user data.

GeekUser.java

Step 3: Create Main Class

Create GeekUserZerocodeApplication class .

GeekUserZerocodeApplication.java

We have to write a scenario to test the same->

{

"scenarioName": "geek test user creation endpoint",

"steps": [ // Array of JSON objects, as much we want we can store

{

"name": "geek_test_successful_creation",

"url": "/api/users", // Relative URL

"method": "POST",

"request": {

"body": { // We have to specify whole bean class parameter and its values

"firstName": "Rachel",

"lastName": "Green",

"departmentName":"IT",

"salary":100000.0

}

},

"verify": { // expected part containing status and body

"status": 201, // status code for a given HTTP call

"body": { // Resultant body from the call

"id": "$NOT.NULL",

"firstName": "Rachel",

"lastName": "Green",

"departmentName":"IT",

"salary":100000.0

}

}

}

}

The above one is a success call that creates a user. Similarly, we can do for validation part as well

{

"name": "test_firstname_validation",

"url": "/api/users",

"method": "POST",

"request": {

"body": {

"firstName": "",

"lastName": "Bing",

"departmentName":"IT",

"salary":100000.0

}

},

"assertions": {

"status": 400,

"rawBody": "firstName can't be empty!"

}

},

{

"name": "test_lastname_validation",

"url": "/api/users",

"method": "POST",

"request": {

"body": {

"firstName": "Monica",

"lastName": "",

"departmentName":"Chef",

"salary":100000.0

}

},

"assertions": {

"status": 400,

"rawBody": "lastName can't be empty!"

}

},

{

"name": "test_departmentname_validation",

"url": "/api/users",

"method": "POST",

"request": {

"body": {

"firstName": "Phoebe",

"lastName": "Buffe",

"departmentName":"",

"salary":50000.0

}

},

"assertions": {

"status": 400,

"rawBody": "DeparmentName can't be empty!"

}

}

We can combine everything together and keep it under the test/resources folder. Basically, it is a JSON file and combines all the entries that are getting tested. Now coming to the test file part

  • @RunWith(ZeroCodeUnitRunner.class) - >eroCodeUnitRunner, as it is responsible for it.
  • @TargetEnv – >Provide the property file that is required for running the scenario.

GeekUserEndpointIT.java

rest_api.properties

web.application.endpoint.host=http://localhost/ # In case of changes they need to be modified appropriately web.application.endpoint.port=8080
web.application.endpoint.context=

For the execution of tests, in pom.xml necessary dependencies are added

We can run the project in the command line by using

URL:

mvn verify -Dskip.it=false

Under the target folder of the directory, we can see multiple files that help to understand different layers of testing

👁 Image
 

Similarly whatever testing scenarios given are validated against Zerocode.

👁 Image
Comment

Explore