Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
How to Test Spring Boot Project using ZeroCode?
Next article icon

How to Test Spring Boot Project using ZeroCode?

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Zerocode automated testing framework for a REST API project concept is getting seen via this tutorial by taking a sample spring boot maven project. Let us see the dependencies for Zerocode :

<dependency>        <groupId>org.jsmart</groupId>        <artifactId>zerocode-tdd</artifactId>        <version>1.3.27</version>        <scope>test</scope>   </dependency>

Zerocode framework supports the following

  • REST
  • SOAP
  • Security
  • Load/Stress
  • Database
  • Apache Kafka
  • GraphQL

In this tutorial let us see REST API testing.

Example Project

Project Structure:

Project Structure
 

pom.xml

XML
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0                          http://maven.apache.org/xsd/maven-4.0.0.xsd">        <modelVersion>4.0.0</modelVersion>     <groupId>com.gfg.zerocode</groupId>     <artifactId>zerocode</artifactId>     <packaging>jar</packaging>     <version>1.0-SNAPSHOT</version>        <dependencies>         <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-web</artifactId>             <version>${spring.boot.version}</version>         </dependency>         <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-test</artifactId>             <version>${spring.boot.version}</version>             <scope>test</scope>         </dependency>         <dependency>             <groupId>org.jsmart</groupId>             <artifactId>zerocode-tdd</artifactId>             <version>${zerocode-tdd.version}</version>             <scope>test</scope>         </dependency>     </dependencies>      <build>         <plugins>             <plugin>                 <groupId>org.springframework.boot</groupId>                 <artifactId>spring-boot-maven-plugin</artifactId>                 <configuration>                     <profiles>                         <profile>it</profile>                     </profiles>                 </configuration>                 <executions>                     <execution>                         <id>pre-integration-test</id>                         <goals>                             <goal>start</goal>                         </goals>                         <configuration>                             <skip>${skip.it}</skip>                         </configuration>                     </execution>                     <execution>                         <id>post-integration-test</id>                         <goals>                             <goal>stop</goal>                         </goals>                         <configuration>                             <skip>${skip.it}</skip>                         </configuration>                     </execution>                 </executions>             </plugin>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-failsafe-plugin</artifactId>                 <version>${maven-failsafe-plugin.version}</version>                 <configuration>                     <skip>${skip.it}</skip>                 </configuration>                 <dependencies>                     <dependency>                         <groupId>org.apache.maven.surefire</groupId>                         <artifactId>surefire-junit47</artifactId>                         <version>${surefire-junit47.version}</version>                     </dependency>                 </dependencies>                 <executions>                     <execution>                         <goals>                             <goal>integration-test</goal>                             <goal>verify</goal>                         </goals>                     </execution>                 </executions>             </plugin>         </plugins>     </build>      <properties>         <maven-failsafe-plugin.version>3.0.0-M5</maven-failsafe-plugin.version>         <surefire-junit47.version>3.0.0-M5</surefire-junit47.version>         <maven.compiler.source>8</maven.compiler.source>         <maven.compiler.target>8</maven.compiler.target>         <spring.boot.version>2.4.2</spring.boot.version>         <skip.it>true</skip.it>         <zerocode-tdd.version>1.3.27</zerocode-tdd.version>     </properties>  </project> 

To test REST API, let us create a sample spring boot application. Let us create the model class first

GeekUser.java

Java
public class GeekUser {        private String id;     private String firstName;     private String lastName;     private String departmentName;        public String getDepartmentName() {         return departmentName;     }      public void setDepartmentName(String departmentName) {         this.departmentName = departmentName;     }      public float getSalary() {         return salary;     }      public void setSalary(float salary) {         this.salary = salary;     }      private float salary;      public String getId() {         return id;     }      public void setId(String id) {         this.id = id;     }      public String getFirstName() {         return firstName;     }      public void setFirstName(String firstName) {         this.firstName = firstName;     }      public String getLastName() {         return lastName;     }      public void setLastName(String lastName) {         this.lastName = lastName;     } } 

GeekUserZerocodeApplication.java

Java
import java.util.ArrayList; import java.util.List; import java.util.UUID;  import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*;  @SpringBootApplication @RestController @RequestMapping("/api/users") public class GeekUserZerocodeApplication {     private List<GeekUser> users = new ArrayList<>();      public static void main(String[] args) {         SpringApplication.run(GeekUserZerocodeApplication.class, args);     }      @PostMapping     public ResponseEntity create(@RequestBody GeekUser user) {         if (!StringUtils.hasText(user.getFirstName())) {             return new ResponseEntity("firstName can't be empty!", HttpStatus.BAD_REQUEST);         }         if (!StringUtils.hasText(user.getLastName())) {             return new ResponseEntity("lastName can't be empty!", HttpStatus.BAD_REQUEST);         }         if (!StringUtils.hasText(user.getDepartmentName())) {             return new ResponseEntity("DeparmentName can't be empty!", HttpStatus.BAD_REQUEST);         }         if (user.getSalary() < 0 ) {             return new ResponseEntity("Salary is not valid!", HttpStatus.BAD_REQUEST);         }         user.setId(UUID.randomUUID()             .toString());         users.add(user);         return new ResponseEntity(user, HttpStatus.CREATED);     }  } 

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) - ZeroCodeUnitRunner, as it is responsible for it
  • @TargetEnv – Provide the property file that is required for running the scenario

GeekUserEndpointIT.java

Java
import org.jsmart.zerocode.core.domain.Scenario; import org.jsmart.zerocode.core.domain.TargetEnv; import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner; import org.junit.Test; import org.junit.runner.RunWith;  // Here in RunWith it has been specified // as ZeroCodeUnitRunner, as it is responsible @RunWith(ZeroCodeUnitRunner.class) // @TargetEnv – this points to the property file  // that will be used when our scenario runs @TargetEnv("rest_api.properties") public class GeekUserEndpointIT {      @Test     @Scenario("rest/geek_user_create_test.json")     public void test_geekuser_creation_endpoint() {     }  } 

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

<plugin>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-failsafe-plugin</artifactId>      <version>3.0.0-M5</version>      <dependencies>          <dependency>              <groupId>org.apache.maven.surefire</groupId>              <artifactId>surefire-junit47</artifactId>              <version>3.0.0-M5</version>          </dependency>      </dependencies>      <executions>          <execution>              <goals>                  <goal>integration-test</goal>                  <goal>verify</goal>              </goals>          </execution>      </executions>  </plugin>

We can run the project in the command line by using

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

 

Similarly whatever testing scenarios given are validated against Zerocode

 

Next Article
How to Test Spring Boot Project using ZeroCode?

P

priyarajtt
Improve
Article Tags :
  • Java
  • Technical Scripter
  • Software Testing
  • Technical Scripter 2022
  • Java-Spring-Boot
Practice Tags :
  • Java

Similar Reads

    How to Send Images in Spring Boot without using Servlet and Redundant JSP Codes?
    Open IntelliJ IDE and in the Controller section of your project inside the Controller class you need to build the Image serve method. The Image serve method looks like below and as you have to collect the Image response use @GetMapping Annotation to collect the image. ImageHandler Controller Method
    2 min read
    How to Create Todo List API using Spring Boot and MySQL?
    Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and se
    6 min read
    Spring Boot - Transaction Management Using @Transactional Annotation
    The @Transactional annotation is the metadata used for managing transactions in the Spring Boot application. To configure Spring Transaction, this annotation can be applied at the class level or method level. In an enterprise application, a transaction is a sequence of actions performed by the appli
    9 min read
    Spring Boot - Map Entity to DTO using ModelMapper
    In enterprise applications, we use RESTful services to establish the communication between client and server. The general idea is that the client sends the request to the server and the server responds to that request with some response. Generally, we have three different layers in most of the appli
    8 min read
    Spring Boot | How to consume JSON messages using Apache Kafka
    Apache Kafka is a stream processing system that lets you send messages between processes, applications, and servers. In this article, we will see how to publish JSON messages on the console of a Spring boot application using Apache Kafka. In order to learn how to create a Spring Boot project, refer
    3 min read
    Spring Boot | How to consume string messages using Apache Kafka
    Apache Kafka is a publish-subscribe messaging queue used for real-time streams of data. A messaging queue lets you send messages between processes, applications, and servers. In this article we will see how to send string messages from apache kafka to the console of a spring boot application.  Appro
    3 min read
    Spring Boot | How to publish String messages on Apache Kafka
    Apache Kafka is a publish-subscribe messaging system. A messaging queue lets you send messages between processes, applications, and servers. In this article, we will see how to send string messages to Apache Kafka in a spring boot application. In order to learn how to create a spring boot project, r
    2 min read
    Spring Boot | How to publish JSON messages on Apache Kafka
    Apache Kafka is a publish-subscribe messaging system. A messaging queue lets you send messages between processes, applications, and servers. In this article, we will see how to send JSON messages to Apache Kafka in a spring boot application. In order to learn how to create a spring boot project, ref
    4 min read
    Spring Boot - Consume JSON Object From Kafka Topics
    Apache Kafka is a publish-subscribe messaging system. A messaging system lets someone is sending messages between processes, applications, and servers. Broadly Speaking, Apache Kafka is software where topics (A topic might be a category) can be defined and further processed. Applications may connect
    4 min read
    Spring Boot Kafka Producer Example
    Spring Boot is one of the most popular and most used frameworks of Java Programming Language. It is a microservice-based framework and to make a production-ready application using Spring Boot takes very less time. Spring Boot makes it easy to create stand-alone, production-grade Spring-based Applica
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences