Skip to content

Testing

The Test panel in LitePost lets you define assertions that automatically run after each HTTP request. You configure assertions through UI dropdowns — no hand-coding required for basic checks. For advanced scenarios, LitePost also supports JavaScript-based test scripts with a Postman-compatible pm API.

Assertion Types

Each assertion targets a specific part of the response. You select the type, a comparison operator, and an expected value from the Test panel's dropdown interface.

Status

Validate the HTTP status code returned by the response.

OperatorExamplePasses when
equalsStatus equals 200Status code is exactly 200
greaterThanStatus greaterThan 199Status code is 200 or more
lessThanStatus lessThan 400Status code is under 400

This is the most common assertion. A quick Status equals 200 check confirms the request succeeded before you inspect the body.

JSON

Validate a value at a specific JSON path in the response body. Paths use dot notation to traverse nested objects and bracket notation for arrays.

JSON PathOperatorExpectedPasses when
data.user.nameequals"Alice"The nested name field is exactly "Alice"
data.itemsexistsThe items key is present in data
data.countgreaterThan0The count value is at least 1
messagecontains"success"The message string includes "success"

Paths are evaluated against the parsed JSON response. If the path does not resolve (e.g., the key is missing), the assertion fails unless the operator is exists with a negated expectation.

Validate the value of a response header.

Header NameOperatorExpectedPasses when
Content-Typecontains"json"Content-Type header includes "json"
Cache-Controlequals"no-cache"Cache-Control is exactly "no-cache"
X-Request-IdexistsThe X-Request-Id header is present

Header name matching is case-insensitive, consistent with the HTTP specification.

Response Time

Validate how long the request took to complete. Timing values are in milliseconds.

OperatorExpectedPasses when
lessThan500Total response time is under 500ms
greaterThan100Response took more than 100ms
equals200Response time is exactly 200ms

Response time assertions are useful for performance monitoring. The lessThan operator is the most practical choice here — exact equality on timing is rarely meaningful.

Operators

All assertion types share the same set of comparison operators:

OperatorDescription
equalsExact match (strict equality for numbers, string match for text)
containsThe actual value includes the expected value as a substring
existsThe target (header, JSON path, etc.) is present in the response
greaterThanNumeric comparison, actual > expected
lessThanNumeric comparison, actual < expected

Test Scripts

For more complex validation logic, LitePost supports JavaScript-based test scripts with a Postman-compatible pm API. You write these in the script editor within the Test panel.

The pm API

Defining Tests

Use pm.test() to define named test cases. Each test receives a callback function where you write your assertions.

javascript
pm.test("Status code is 200", function () {
  pm.expect(pm.response.code).to.equal(200);
});

Assertions with pm.expect

pm.expect(value) provides chai-like assertion chaining:

javascript
pm.test("Response contains user data", function () {
  const body = pm.response.json();
  pm.expect(body.data).to.have.property("name");
  pm.expect(body.data.name).to.equal("Alice");
});

Accessing the Response

pm.response exposes properties of the received response:

javascript
pm.test("Comprehensive response check", function () {
  // Status code
  pm.expect(pm.response.code).to.equal(200);

  // Parse the JSON body
  const data = pm.response.json();
  pm.expect(data.items.length).to.be.greaterThan(0);
});

Combining Dropdowns and Scripts

You can use both dropdown assertions and test scripts on the same request. Dropdown assertions run first, followed by any scripts. Both sets of results appear together in the test results display.

javascript
// Script-based test alongside dropdown assertions
pm.test("User array is not empty", function () {
  const users = pm.response.json().data.users;
  pm.expect(users.length).to.be.greaterThan(0);
});

pm.test("First user has an email", function () {
  const firstUser = pm.response.json().data.users[0];
  pm.expect(firstUser).to.have.property("email");
});

Test Results Display

After a request completes, the Test panel shows results for every assertion and test script:

  • Pass: The assertion succeeded. Displayed with a green indicator and the assertion description.
  • Fail: The assertion did not hold. Displayed with a red indicator, the assertion description, and an error message explaining what went wrong (e.g., "Expected 200 but received 404").

Each result is listed individually, so you can see at a glance which checks passed and which need attention.

Tests in the Collection Runner

When you execute a collection through the Collection Runner, every request's assertions run automatically after that request completes. This turns your collection into a repeatable test suite.

  • Assertions defined on each request (both dropdown and script-based) execute in order as the runner processes the collection.
  • The runner summary shows aggregate results: total assertions, pass count, and fail count.
  • Failed assertions are highlighted with the request name and failure details, so you can identify which endpoint in the collection broke and why.

TIP

Define assertions on each request in a collection before running the Collection Runner. This gives you a full pass/fail report across your entire API workflow in a single run.

This workflow is especially useful for regression testing — save a collection of critical endpoints with their assertions, then re-run the collection after backend changes to verify nothing is broken.

Released under the AGPL-3.0 License.