-
Notifications
You must be signed in to change notification settings - Fork 0
JPostman Tutorial Part 1: JPostman Setup and create a Java Maven API Testing Project
-
Video tutorial: https://www.youtube.com/watch?v=UxFjeONEq60
This tutorial explains how to create a Java Maven API testing project using JPostman, a lightweight Java library that lets you reuse exported Postman collections and environments directly in Java API tests.
With JPostman, you can export a Postman collection and environment, add them to a Maven project, and execute API requests from Java test code.
By the end of this tutorial, you will know how to:
- Review a Postman collection and environment.
- Export a Postman environment JSON file.
- Export a Postman collection JSON file.
- Create a Java Maven project in Eclipse.
- Add JPostman and TestNG dependencies.
- Add exported Postman JSON files to
src/test/resources. - Create a simple Java test class.
- Load the collection and environment using JPostman.
- Run the test with TestNG.
Before starting, make sure you have:
- Java JDK 11 or higher.
- Eclipse IDE, or another Java IDE that supports Maven.
- Maven support enabled in your IDE.
- Postman installed.
- A Postman collection and environment ready for export.
- Basic knowledge of Java and Maven.
The tutorial uses a Postman collection based on DummyJSON, a free fake REST API that provides placeholder JSON data for development, testing, and prototyping.
The example collection includes requests such as:
- Login
- Get current authenticated user
- Product APIs
- Dynamic image APIs
Before exporting the collection, review the Postman environment used for testing.
Example environment variables include:
base_url
username
password
accessToken
These variables allow requests in the Postman collection to use dynamic values instead of hardcoded URLs, credentials, or tokens.
To export the environment:
- Open Postman.
- Locate the
DummyJSONenvironment. - Click the three dots next to the environment.
- Select Export.
- Save the environment JSON file into your Java project resources directory.
Recommended location:
src/test/resources
Postman requests can reference environment variables using double curly braces.
Example:
{{base_url}}
{{username}}
{{password}}
{{accessToken}}
JPostman resolves these placeholders from the exported environment before executing the request.
To export the collection:
- Open Postman.
- Locate the
DummyJSONcollection. - Click the three dots next to the collection.
- Select More actions.
- Choose Export.
- Save the collection JSON file into the same resources directory.
Recommended location:
src/test/resources
In Eclipse:
- Click Create a Maven project.
- Select Create a simple project.
- Click Next.
- Enter the Maven project details.
Example:
Group ID: com.example
Artifact ID: jpostman-demo
- Click Finish.
After the Maven project is created:
- Expand the project in Eclipse.
- Open the
pom.xmlfile. - Add the JPostman dependency inside the
<dependencies>section.
Maven Central Repository - JPostman
Example:
<dependencies>
<dependency>
<groupId>io.github.jpostman</groupId>
<artifactId>jpostman-core</artifactId>
<version>REPLACE_WITH_LATEST_VERSION</version>
</dependency>
</dependencies>jpostman-core is the main JPostman library. Other JPostman packages are optional REST API executor adapters.
The tutorial uses TestNG for running Java test scripts.
Add TestNG to the pom.xml file:
Maven Central Repository - TestNG
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>REPLACE_WITH_TESTNG_VERSION</version>
<scope>test</scope>
</dependency>You can also use another test framework such as JUnit, Cucumber, or any framework that works with your project.
After updating pom.xml:
- Right-click the project or
pom.xml. - Go to Maven.
- Select Update Project.
- Enable Force Update of Snapshots/Releases.
- Click OK.
This downloads the required dependencies.
Create a test class under:
src/test/java
Example class name:
DemoTest
In Eclipse:
- Right-click
src/test/java. - Select New.
- Select Class.
- Enter the class name.
- Click Finish.
Make sure the project uses JDK 11 or higher.
In Eclipse:
- Right-click JRE System Library.
- Open Properties.
- Select Alternate JRE.
- Choose Java 11 or higher.
- Click Apply and Close.
The tutorial example uses Java 17.
Drag both exported Postman JSON files into:
src/test/resources
You should have:
src/test/resources
├── DummyJSON.postman_collection.json
└── DummyJSON.postman_environment.json
File names may be different depending on how you exported them from Postman.
Add TestNG and JPostman imports:
import org.testng.annotations.Test;
import io.jpostman.JPostman;
import io.jpostman.JPostman.Context;Create a test method:
public class DemoTest {
@Test
public void test1() throws Exception {
Context cxt = JPostman. Load(getClass().getResourceAsStream("DummyJSON.postman_collection.json"),
getClass().getResourceAsStream("DummyJSON.postman_environment.json"));
System.out.println(cxt.getEnvironment().toDebugString());
System.out.println(cxt.getCollection().toDebugString());
}
}The test loads the exported Postman collection and environment from the project resources folder, then prepares them for execution through JPostman.
To run the Java test:
- Save the Java test class.
- Right-click the test file.
- Select Run As.
- Choose TestNG Test.
If the setup is correct, the project should run successfully with the JPostman configuration.
A typical project structure should look like this:
jpostman-demo
├── pom.xml
└── src
└── test
├── java
│ └── DemoTest.java
└── resources
├── DummyJSON.postman_collection.json
└── DummyJSON.postman_environment.json
JPostman provides the main core library and optional executor adapters.
Common modules include:
| Module | Purpose |
|---|---|
jpostman-core |
Main JPostman library |
jpostman-httpclient |
Java HttpClient executor adapter |
jpostman-restassured |
REST Assured executor adapter |
jpostman-playwright |
Playwright executor adapter |
jpostman-unirest |
Unirest executor adapter |
For this setup tutorial, start with:
jpostman-core
Additional adapters can be added later depending on the API execution strategy you want to use.
In this tutorial, you created a Java Maven API testing project and configured it to use JPostman. You exported a Postman collection and environment, added them to the Maven test resources folder, configured dependencies, created a TestNG test class, and ran the test from Eclipse.
The next tutorial will show how to execute multiple API requests using Java HttpClient, REST Assured, Playwright, and Unirest.
- Video tutorial: https://www.youtube.com/watch?v=UxFjeONEq60
- GitHub documentation and examples: https://github.com/JPostman/jpostman
- DummyJSON API: https://dummyjson.com