Create a Test
Bruno uses the Chai library (opens in a new tab), so you can follow the same syntax for writing assertions in your tests.
To ensure your API is behaving as expected, create a test against it.
Bruno supports writing tests by through either:
- Assertions to declaratively write tests
- JavaScript
Assertion
To get familiar with testing, open a Collection, select a request, and click on the Assertions
tab
You can then dictate an expression, operator, and value to test against.
Testing with JavaScript
Bruno also supports writing automation test scripts in JavaScript for more advanced API testing scenarios. By automating your tests, you can increase efficiency and coverage, and integrate testing into CI/CD pipelines.
Example
test("should be able to login", function () {
const data = res.getBody();
expect(res.getStatus()).to.equal(200);
});
test("should return json", function () {
const data = res.getBody();
expect(res.getBody()).to.eql({
hello: "Bruno",
});
});
In this example:
- The first test checks that the response status is 200 (indicating a successful login).
- The second test verifies that the response body is equal to the expected JSON object.
For more advanced testing scenarios and tips, view the Scripting (opens in a new tab) docs.