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.
GUI-Based Assertions
Thunder Client's GUI-based assertions simplify the testing process. Here's what you can do with them:
- String, Number, Count, and Type Checking: You can easily set up tests for different data types and conditions.
- JSON Schema Validation: Validate your API responses against a JSON schema without writing any code.
- Rearranging Tests: Organize your test order with a simple drag-and-drop 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.
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.
- When you get an XML response, select Convert To Json.
- Use the Json Query dropdown to perform your tests.
- Save response properties to the environment using the Set Env Variable dropdown.
Schema Validation
Validating responses against a JSON schema in Thunder Client is straightforward:
- Create a schema file in your workspace.
- Save the path of the schema file in an environment variable.
- 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"
}
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);
});
EchoAPI for VS Code: A Recommended Alternative
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.
Advantages of EchoAPI:
- No login required
- Supports Scratch Pad
- Ultra lightweight
- 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.
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!