Skip to content

JPostman Tutorial Part 1: JPostman Setup and create a Java Maven API Testing Project

David Gofman edited this page Jun 15, 2026 · 7 revisions

Create a Java Maven API Testing Project

Overview

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.

What You Will Learn

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.

Prerequisites

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.

Example API Used in the Tutorial

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

Step 1: Review the Postman Environment

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.

Step 2: Export the Postman Environment

To export the environment:

  1. Open Postman.
  2. Locate the DummyJSON environment.
  3. Click the three dots next to the environment.
  4. Select Export.
  5. Save the environment JSON file into your Java project resources directory.

Recommended location:

src/test/resources

Step 3: Review Template Variables in Postman

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.

Step 4: Export the Postman Collection

To export the collection:

  1. Open Postman.
  2. Locate the DummyJSON collection.
  3. Click the three dots next to the collection.
  4. Select More actions.
  5. Choose Export.
  6. Save the collection JSON file into the same resources directory.

Recommended location:

src/test/resources

Step 5: Create a Java Maven Project

In Eclipse:

  1. Click Create a Maven project.
  2. Select Create a simple project.
  3. Click Next.
  4. Enter the Maven project details.

Example:

Group ID: com.example
Artifact ID: jpostman-demo
  1. Click Finish.

Step 6: Add JPostman Dependency

After the Maven project is created:

  1. Expand the project in Eclipse.
  2. Open the pom.xml file.
  3. 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.

Step 7: Add TestNG Dependency

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.

Step 8: Update the Maven Project

After updating pom.xml:

  1. Right-click the project or pom.xml.
  2. Go to Maven.
  3. Select Update Project.
  4. Enable Force Update of Snapshots/Releases.
  5. Click OK.

This downloads the required dependencies.

Step 9: Create a Java Test Class

Create a test class under:

src/test/java

Example class name:

DemoTest

In Eclipse:

  1. Right-click src/test/java.
  2. Select New.
  3. Select Class.
  4. Enter the class name.
  5. Click Finish.

Step 10: Configure JDK 11 or Higher

Make sure the project uses JDK 11 or higher.

In Eclipse:

  1. Right-click JRE System Library.
  2. Open Properties.
  3. Select Alternate JRE.
  4. Choose Java 11 or higher.
  5. Click Apply and Close.

The tutorial example uses Java 17.

Step 11: Add Postman JSON Files to Resources

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.

Step 12: Write a Basic Test

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.

Step 13: Run the Test

To run the Java test:

  1. Save the Java test class.
  2. Right-click the test file.
  3. Select Run As.
  4. Choose TestNG Test.

If the setup is correct, the project should run successfully with the JPostman configuration.

Maven Project Structure

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 Maven Modules

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.

Summary

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.

Related Links

Clone this wiki locally