Bruno API Test Scripts
Bruno API Test Scripts
Bruno is an open-source API testing tool that uses JavaScript for writing automation test scripts. It leverages the Chai assertion library
for writing assertions, making it familiar for developers already experienced with JavaScript testing frameworks. Bruno operates completely offline, ensuring your data remains secure without relying on external servers.
Bruno Test Scripts
JavaScript-based Scripting: Write tests using JavaScript, allowing for flexible and powerful test logic.
Chai Assertion Library: Use expressive assertions like expect(res.getStatus()).to.equal(200).
Pre-request and Test Scripts: Execute scripts before sending requests (pre-request) and after receiving responses (test scripts).
Environment Variables: Manage variables for different environments (e.g., development, production) using bru.setEnvVar() and bru.getEnvVar().
CI/CD Integration: Run tests in CI/CD pipelines using the Bruno CLI.
How to Write Tests?
- Open Bruno testing tool and choose the API under test in the collection.
-
Click the “Tests” tab
-
Write custom JavaScript tests using Bruno’s scripting API
Example Test
Sample test script code below:
test("Status code should be 200", function() {
expect(res.getStatus()).to.equal(200);
});
test("Response should contain username", function() {
const data = res.getBody();
expect(data.username).to.exist;
});