Thunder Client Guide: How to Use Assertions

This guide will walk you through how to use these GUI-based assertions and introduce you to an alternative tool, EchoAPI for VS Code.

Thunder Client is a revolutionary tool in the API testing landscape, primarily because it's the first to offer GUI-based assertions. Unlike Postman and other clients that require extensive scripting for basic tests, Thunder Client allows you to perform standard tests with a few dropdown selections—no scripting knowledge required. This guide will walk you through how to use these GUI-based assertions and introduce you to an alternative tool, EchoAPI for VS Code.

Thunder Client.png
Thunder Client Guide: How to Achieve Team Collaboration
Thunder Client for VS Code by Ranga Vadhineni offers team collaboration via Git sync, simplicity, and local storage. EchoAPI is also recommended.

GUI-Based Assertions

Thunder Client's GUI-based assertions simplify the testing process. Here's what you can do with them:

  1. String, Number, Count, and Type Checking: You can easily set up tests for different data types and conditions.
  2. JSON Schema Validation: Validate your API responses against a JSON schema without writing any code.
  3. Rearranging Tests: Organize your test order with a simple drag-and-drop interface.
Testing Interface

GUI-based assertions save you from writing boilerplate code, making your testing process smoother and faster.

Array Testing

Thunder Client allows you to test arrays with specific filters. These filters include operations such as contains (*=), startsWith (^=), and endsWith ($=). You can also access array items using negative index numbers.

Array Testing Interface

XML Testing

For XML responses, Thunder Client offers a Convert To Json option. This feature allows you to convert XML responses into JSON format so you can leverage JSON-based assertions.

  1. When you get an XML response, select Convert To Json.
  2. Use the Json Query dropdown to perform your tests.
  3. Save response properties to the environment using the Set Env Variable dropdown.
XML Testing Interface

Schema Validation

Validating responses against a JSON schema in Thunder Client is straightforward:

  1. Create a schema file in your workspace.
  2. Save the path of the schema file in an environment variable.
  3. Select the schema option in the Tests tab and use the readFile filter.

Sample Schema:

{
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "fraction": { "type": "number" },
        "balance": { "type": "number" },
        "bignumber": { "type": "integer" },
        "isNumber": { "type": "null" }
    },
    "required": ["balance", "bignumber", "fraction", "isNumber"],
    "title": "Welcome4"
}
Schema Validation Interface
Thunder Client Guide: How to Set Up REST API Authentication Parameters and Cookies
Thunder Client is a lightweight REST API client extension available in Visual Studio Code (VS Code). It’s designed to be fast, lightweight, and easy to use, making it perfect for developers who need a quick and efficient way to test their APIs.

Script-Based Assertions (Paid Feature)

For more advanced testing requirements, Thunder Client's paid version allows you to write custom test assertions using JavaScript or the Chai library.

Basic Assertion Example:

let success = tc.response.status == 200;
let json = tc.response.json;
let containsThunder = json.message?.includes("thunder");

tc.test("Response code is 200", success);
tc.test("Response contains thunder word", containsThunder);

Chai Assertion Example:

tc.test("Response code expect to be 200", function () {
    expect(tc.response.status).to.equal(200);
});

tc.test("Response code is 200", function () {
    assert.equal(tc.response.status, 200);
});

If you're seeking an alternative to Thunder Client, consider EchoAPI for VS Code. It's a lightweight, collaborative tool for API development and testing, supporting features like Scratch Pad, API design, debugging, automated testing, and load testing—all without the need to log in.

An Alternative to Consider: EchoAPI.png

Advantages of EchoAPI:

  1. No login required
  2. Supports Scratch Pad
  3. Ultra lightweight
  4. 100% compatible with Postman script syntax

EchoAPI comes with plugins for IntelliJ IDEA, VS Code, and even a Chrome request capture extension, making it a robust alternative for developers looking for more flexibility and ease of use.

EchoAPI for VS Code.png

By leveraging the advanced features of Thunder Client and considering EchoAPI as an alternative, you can significantly enhance your efficiency in API testing. Happy testing!