JSON (JavaScript Object Notation) is the go-to format for sending and receiving data in modern web...
Using Cursor to Generate API Tests in Bruno
Most of us are increasingly turning to AI-powered tools, and for good reason... it's wildly efficient especially for redundant or tedious tasks. One great example is using Bruno, the Git-based API client, with Cursor, the AI-powered IDE.
What makes this combination possible is Bruno's unique approach to storing API collections and requests as plaintext files, making them easily readable and modifiable in any code editor.
At Bruno, we believe in making API testing as efficient as possible. By storing collections as plaintext files, Bruno enables seamless integration with modern development tools like Cursor / Copilot / Augment / Etc. This means you can leverage AI assistance directly on your API collections, right in your code editor.
Here's how to set it up and make the most of this powerful combination.
Why Bruno's File-Based Approach Matters
- Plaintext Collections
- Bruno stores all collections as plaintext files (`.bru`), making them easily readable and editable in any code editor
- No proprietary binary formats or databases to deal with
- Collections can be version controlled, diffed, and merged just like any other code
- Editor Integration
- Because collections are plaintext, they can be opened and edited in any code editor
- This enables powerful integrations with any IDE-based coding assistant
- No need to switch between different tools or interfaces
- Developer Experience
- Work with your API collections using the same tools and workflows you use for code
- Leverage editor features like syntax highlighting, code completion, and AI assistance
- Maintain consistency in your development environment
Bruno + Cursor: A Powerful Combination
- AI-powered test generation
Cursor can help generate tests for your Bruno collections by understanding the structure of your API requests and responses. Here's how it works:
The collection/request you have living in the Bruno appcan be opened directly in your IDE:
- Intelligent test suggestions
Cursor can analyze your API responses and suggest appropriate tests based on the data structure and common patterns. - Automated test maintenance
When your API changes, Cursor can help update your tests to match the new structure. - Smart documentation
Cursor can help generate and maintain documentation for your API tests, making them more maintainable.
(Optional) Fine-tune Cursor for Bruno Development
Out of the box, Cursor (and other coding assistants) works fine with Bruno, but you can bring it to the next level by providing a bit of guidance. This is optional but recommended.
Below is a configuration file that can be placed in the root of your workspace, either in a .cursor
directory, or just as a file like .bru-
test-config.json
.
I've set this configuration file specifically for testing, so it won't create new requests or folders for you but feel free to modify it as you'd like. We have users that are automatically updating collections based on code changes, or having documentation auto-generated for them. There's a ton of possibility here.
{
"bru_test_config": {
"file_rules": {
"base_path": ".",
"allowed_paths": ["*.bru"],
"forbidden_actions": [
"create_new_files",
"create_new_folders",
"modify_paths"
],
"edit_rules": {
"must_use_existing_path": true,
"must_use_relative_paths": true
}
},
"test_structure": {
"required_sections": [
"tests { ... }",
"docs { ... }"
],
"test_format": "test(\"test name\", () => { ... })",
"common_test_categories": [
"request_structure",
"response_status",
"response_body",
"data_validation"
]
},
"bru_methods": {
"request": {
"get_body": "req.getBody()",
"get_headers": "req.getHeaders()",
"get_params": "req.getParams()"
},
"response": {
"get_status": "res.getStatus()",
"get_body": "res.getBody()",
"get_headers": "res.getHeaders()"
}
},
"assertion_patterns": {
"property_exists": "expect(obj).to.have.property('prop')",
"type_check": "expect(value).to.be.a('type')",
"array_check": "expect(arr).to.be.an('array')",
"status_check": "expect(res.getStatus()).to.equal(200)",
"value_equals": "expect(value).to.equal(expected)",
"array_length": "expect(arr).to.have.lengthOf(n)",
"array_contains": "expect(arr).to.include(value)"
},
"common_test_patterns": {
"request_structure": `
test("Validate request structure", () => {
const body = req.getBody();
// Check top-level properties
expect(body).to.have.property('propName');
expect(body.propName).to.be.a('type');
// Check nested structures
const nested = body.propName;
expect(nested).to.have.property('nestedProp');
});
`,
"response_validation": `
test("Validate response", () => {
expect(res.getStatus()).to.equal(200);
const responseBody = res.getBody();
expect(responseBody).to.be.an('object');
});
`,
"array_validation": `
test("Validate array contents", () => {
const items = req.getBody().items;
expect(items).to.be.an('array');
items.forEach(item => {
expect(item).to.have.property('requiredProp');
});
});
`,
"data_type_validation": `
test("Validate data types", () => {
const data = req.getBody().data;
expect(data.id).to.be.a('number');
expect(data.name).to.be.a('string');
expect(data.items).to.be.an('array');
});
`
},
"best_practices": {
"test_organization": [
"Group related tests together",
"Use descriptive test names",
"Test one concept per test",
"Include both positive and negative cases"
],
"validation_priorities": [
"Request structure first",
"Response status second",
"Response body structure third",
"Data validation last"
],
"error_handling": [
"Test for required fields",
"Validate data types",
"Check array contents",
"Verify nested structures"
]
}
}
}
Example Workflow
- Create a new API request
- Let Cursor generate tests
Cursor will analyze your request and suggest appropriate tests based on the request type and body structure. - Review and customize
Review the generated tests and customize them to match your specific requirements. - Run and verify
Use Bruno to run your tests and verify that they work as expected.
Best Practices for Bruno + Cursor
- Consistent naming conventions
Use clear, descriptive names for your requests and tests to help Cursor understand your collection structure. - Structured test organization
Organize your tests in a way that makes sense for your API, making it easier for Cursor to generate and maintain them. - Documentation first
Include clear documentation in your Bruno files to help Cursor understand the purpose and expected behavior of each request.
Key Benefits
- Faster test creation — Generate tests automatically based on your API structure
- Reduced maintenance — Keep tests up-to-date with minimal effort
- Better documentation — Maintain clear documentation of your API tests
- Improved productivity — Spend less time on test maintenance and more time on development
Getting Started
- Install the tools: Bruno and Cursor
- Set up your environment: Configure Cursor to work with Bruno collections
- Create your first collection: Start with a simple API and let Cursor help you generate tests
- Join the community: Share your experiences and learn from others in our Discord community
Conclusion
By combining Bruno's powerful API testing capabilities with Cursor's AI assistance, you can create a more efficient and productive development environment. The key is to set up your environment correctly and follow best practices for organizing your collections and tests. With the right setup, you can significantly reduce the time spent on test creation and maintenance, allowing you to focus on what matters most: building great APIs.