Validation

Welcome to PruTAN's Validation feature — a powerful testing framework that enables you to write automated tests to validate API responses after execution. With Validation, you can ensure your APIs are working correctly by checking response status codes and body content, making your API testing more robust and reliable.

Overview

PruTAN's validation is post-validation of responses, executed after a response is received from the server. This allows you to write test suites that verify the correctness of your API responses.


Writing Validation Scripts

PruTAN provides a validation object called pv (PruTAN Validator) for writing post-response validation scripts. Each assertion is wrapped in a pv.test(...) call whose first argument is the test label and whose remaining arguments are one or more checks performed on the response object res.

Common Validation Examples

Here are the main validation patterns available in PruTAN for REST APIs:

Status Code Validation

Purpose: Verify that the response status code matches the expected value.

// Check status code is 200
pv.test("Status code is 200", res.validateResponse("200"));

Response Body Value Assertion

Purpose: Assert that a specific field in the response body has — or does not have — a given value.

// Field equals an expected value
res.isValuePresent("paymentId", "pi0105ARZ3NDEKTSV4RRFFQ69G5FAV");

// Field does NOT equal a given value
res.isValueNotPresent("paymentStatus", "FAILED");

Response Body Field Existence

Purpose: Check whether a specific field exists in the response body.

// Field must be present in the response body
res.isFieldPresent('paymentId');

// Field must NOT be present in the response body
res.isFieldNotPresent('paymentStatus');

Example: Validating a Payment Response

The scripts above validate a POST /payments response. A single pv.test block can group multiple related assertions under one test label:

// Check status code is 200
pv.test("Status code is 200", res.validateResponse("200"));

// Check response property
pv.test("Validate response properties",
    res.isValuePresent("paymentId", "pi0105ARZ3NDEKTSV4RRFFQ69G5FAV"),
    res.isValuePresent("paymentStatus", "SUCCEEDED"),
    res.isValueNotPresent("paymentStatus", "FAILED"),
    res.isFieldPresent('paymentId'),
    res.isFieldNotPresent('paymentStatus')
);

After the request is sent, the Test Results tab under the response panel reports each assertion:

Test Report

Status code is 200 — 1 successful, out of 1 tests.

  • ✓ Expected Response Code to be 200, actual value is 200 — test success

Validate response properties — 1 failing, 4 successful, out of 5 tests.

  • ✓ Expected paymentId to be pi0105ARZ3NDEKTSV4RRFFQ69G5FAV, actual value is pi0105ARZ3NDEKTSV4RRFFQ69G5FAVtest success
  • ✓ Expected paymentStatus to be SUCCEEDED, actual value is SUCCEEDEDtest success
  • ✓ Expected paymentStatus not to be FAILED, actual value is SUCCEEDEDtest success
  • ✓ Expected paymentId field — test success
  • ✗ Not Expected paymentStatus field — test failed
  • The last assertion fails because paymentStatus does exist in the response — isFieldNotPresent only passes when the field is absent. The example intentionally shows both pass and fail outcomes.

Protocol-Specific Validation

Sample scripts for ISO & XML response bodies:

// Check ISO response property by field ID
pv.test("Check ISO response property", res.isValuePresent("3", "10200"));

// Check XML response property using dot notation
pv.test("Check XML response property", res.isValuePresent("root.parent.hobby", "Chess"));

Notes

  • Test Results: Validations are reported in the Test Results tab under the response section.
  • Multiple Tests: You can pass multiple assertions to a single pv.test(...) call, or add multiple pv.test(...) blocks to a request.
  • Sample Templates: Sample templates are provided in the validation tab for reference. Users can click to add sample scripts to the validation tab editor for further customization.

The Validation feature in PruTAN empowers teams to build comprehensive test suites — ensuring APIs perform as expected and catching issues early in the development process.