-
Notifications
You must be signed in to change notification settings - Fork 0
@JPostmanAssert
This page describes the proposed @JPostmanAssert feature for annotation-based JPostman tests.
The goal is to keep test methods small while moving reusable response validation into an assertion rules file. This works with both single-request tests using @JPostmanResponse and folder/root runners using @JPostmanRunner.
Add an assertion rules file to jpostman.properties.
assertions=classpath:jpostman-assertions.iniThis global file can be used by any namespace.
You can also override the assertion file for a specific namespace:
assertions.product=classpath:product-assertions.iniResolution order:
1. @JPostmanAssert(rules = "...")
2. assertions.<namespace>
3. assertions
This means you do not need assertions.product if the global assertions file already contains the product rules. Add assertions.product only when you want a separate file for that namespace.
The assertion file uses INI-style sections.
[default]
statusCode=200
exists=id
[product]
extends=default
exists=title,price
[Add a new product]
extends=product
statusCode=201
pathNotNull=id
pathEquals=minimumOrderQuantity=1The first version supports these assertion keys:
statusCode=200
exists=id,title
notExists=error,message
pathNotNull=id
pathEquals=active=true,quantity=10,name=PhoneRule behavior:
| Rule | Meaning |
|---|---|
statusCode=200 |
Verifies the HTTP response status code. |
exists=id,title |
Verifies that the listed response paths exist. |
notExists=error,message |
Verifies that the listed response paths do not exist. |
pathNotNull=id |
Verifies that the listed response paths are not null. |
pathEquals=active=true |
Verifies that a path equals the expected value. |
A section can extend another section:
[product]
extends=default
exists=title,priceInheritance order is parent first, then child:
default -> product
Child rules override parent rules when the same rule key is defined.
Example:
[default]
statusCode=200
exists=id
[product]
extends=default
exists=title,priceThe resolved product rules become:
statusCode=200
exists=title,priceexists=id from the parent is replaced by exists=title,price from the child.
To keep id, include it again:
[product]
extends=default
exists=id,title,priceIf a section name matches the current Postman request name, that section is applied last and has the highest priority.
Example request:
@JPostmanResponse(
namespace = "product",
folder = "Product",
request = "Add a new product",
log = true
)
@JPostmanAssert(sections = { "product" })
@Test
public void addNewProduct() {
}Assertion file:
[default]
statusCode=200
exists=id
[product]
extends=default
exists=title,price
[Add a new product]
extends=product
statusCode=201
pathNotNull=idFinal order:
default -> product -> Add a new product
Final resolved rules:
statusCode=201
exists=title,price
pathNotNull=idThe request-name section overrides statusCode=200 from [default] with statusCode=201.
@JPostmanResponse(
namespace = "product",
folder = "Product",
request = "Add a new product",
log = true
)
@JPostmanAssert(sections = { "product" })
@Test
public void addNewProduct() {
}When @JPostmanAssert is present, JPostman uses the assertion rules file instead of the default verify() value from @JPostmanResponse.
So this is not needed:
verify = 201The assertion file should define it instead:
[Add a new product]
statusCode=201@JPostmanRunner can execute multiple requests from a folder. @JPostmanAssert applies rules to each executed request.
@JPostmanRunner(
namespace = "product",
folder = "Product",
exclude = { "Add a new product", "Update a product", "Delete a product" },
log = true
)
@JPostmanAssert(sections = { "product" })
@Test
public void runProductReadOnlyRequests() {
}For each request in the folder, JPostman applies:
configured sections + current request-name section if it exists
For example, when the runner executes Get all products, JPostman also checks for:
[Get all products]If that section exists, it is applied last.
Without @JPostmanAssert, JPostman uses the normal annotation verify value:
@JPostmanResponse(request = "Get all products", verify = 200)With @JPostmanAssert, JPostman skips the normal verify() call from @JPostmanResponse or @JPostmanRunner and uses the assertion rules file instead.
This avoids duplicate status checks and keeps all assertion behavior in one place.