Services
About
Portfolio
Careers
Blog
Get in touch
>Services
>About
>Portfolio
>Careers
>>Blog

>> Browse services

>_ProductScope StudioFrom an idea to a shareable PRD_> Open_> Open
>>>Build new0 to 1: MVPs, SaaS, AI features
>>View Build path>Generative AI Solutions>PoC/MVP Development>SaaS Development
>>>Modernize and scale1 to 100: prototype-to-prod, backlog, hybrid
>>View Modernize path>End-to-end Software Development>Prototype to Production>Hybrid Teams
>>>Cross-cuttingStrategy and investor support
>For Investors>Product Consulting
All services hub
Get in touch

Contact

contact@apptension.com+48 793 925 552sales@apptension.com

Company Information

Apptension sp. z o.o.
Górecka 1
60-201 Poznań, Poland
VAT-ID: PL7831720203
REGON: 360404804
KRS: 0000534235

Follow Us

Qa
6 min read
May 23, 2022
Dominik Ciechowski

How to test API with JAVA and RESTASSURED

Here's a straightforward tutorial on running automated API tests using JAVA and RESTASSURED.

How to test API with JAVA and RESTASSURED

Tools required:

  • IntelliJ IDEA,
  • JDK,
  • RestAssured,
  • TestNG,
  • Mockoon.

‍Introduction:

There are many types of queries that applications communicate with each other. The most important, however, are 4 so-called CRUD queries (create, read, update, delete).

The following types of requests suit them:

  • POST, 
  • GET, 
  • PUT, 
  • DELETE.

In order to construct a valid Api request of the tested application, we need to know it:

  • Base URL,
  • Endpoint prefix,
  • Request type,
  • Payload (data sent as an object - required for POST and PUT requests).

‍

‍

How to start writing automated API tests?

‍Creation of a new Type Maven project

First, we need to create a new Maven project in IntelliJ IDEA.

  • Choose File -> New Project:

‍

‍

  • Choose Maven:

‍

  • In the next step, we name the project, e.g. RestAssured, and move on.

‍

Adding dependencies to POM.xml

Adding the dependency to the pom.xml file - these are the entries which plugins are to be “installed” to our project. In our case, we need RestAssured, TestNG and AssertJ:

‍

Creating a new class and writing a new test function

Adding a Java Class file named e.g. MockoonTest to the ...src/test/java directory in the project structure:

‍

In the body of the newly added class, we create a variable of type String and assign it the value base url:

Copying the code for the first test:

  • For the @Test prefix, we import the method from the TestNG library,
  • We create a new method named for example checkStatusCodeWithRestAssured (),
  • In the body of the above method, we use the get function built into the RestAssured library - we also import it,
  • Next, we append the prefix url to the base url to indicate the endpoint address to which we want to send the request,
  • We use the next methods of the Rest Assured library, which are .then and .statusCode to check whether the server returned the 200 code we expected, depending on whether the server returned the 200 code we were expecting or not, the test will be successful or fail.

Before starting the test, run the endpoint simulation, in our case with the prefix "/ testdominik".

How to run the API simulator?

Launching and configuring the Mockoon application

Launch the previously installed Mockoon app and proceed as below:

  1. Click the "plus" button,
  2. Set the query type to "GET",
  3. Set the endpoint prefix to "/ testdominik",
  4. Optionally, in the "Body" field, set the data to be returned by the server, e.g. {response},
  5. Launch the simulator by clicking the green triangle play.

‍

‍How to run our first API test?

Click the green play triangle to the left of the test function and select "Run":

‍

Successful test result:

Qa Practice

>> Related Posts

Continue reading

View all posts
Manual tests extended with security tests using the browser
Qa
8 min

Manual tests extended with security tests using the browser

Qa Practice
Read more

>>>Ready to start your project?

Let's discuss how we can help bring your ideas to life.

contact@apptension.com+48 533 352 052

Services

  • Generative AI Solutions
  • PoC/MVP Development
  • End-to-end Software Development
  • Prototype to Production
  • SaaS Development
  • Hybrid Teams
  • For Investors
  • Product Consulting

Builder's Toolkit

  • Builder's Toolkit
  • SaaS Boilerplate
  • SaaS P&L Model
  • Walkthrough Studio
  • Agentic SDLC
  • Resources
  • Guides
  • Events
  • Open Source
  • Discord Community

Company

  • About Us
  • Portfolio
  • Expertise
  • Careers
  • Blog
  • Get in touch

Company Information

Apptension sp. z o.o.
Górecka 1
60-201 Poznań, Poland
VAT-ID: PL7831720203
REGON: 360404804
KRS: 0000534235

Follow Us

© 2026 Apptension. All rights reserved.

Privacy PolicyTech Radar