#
Generating assertions using AI
Writing assertions from scratch can be a cumbersome task. Most of the time, you just need assertions to check general structure of the API response to get started.
This is where the "Generate using AI" feature for assertions can help you out. Using this, KushoAI looks at your API response and creates a basic set of assertions to check all future API responses match this structure. Note that this will work only when the API response is valid, so this is something that needs to be verified by you.
Here's how you can use this feature to quickly get started with assertions.
- Run a test - you can use the run all option or just run a single test
- Go to "Assertions" tab under test details
- Click on "Generate using AI" button. It might take a couple of seconds for the assertions to get generated
- Add/edit/remove any additional assertions as per your requirement
- Click on "Save and Run". This will save the assertions and run the test again with assertions
- You should see a pass/fail status under "Assertions" column. Along with that, you'll see the status for individual assertions under the "Assertion Results" tab in test details
Please note that these assertions are generated based on your API response. If the response is wrong, the assertions generated will also be wrong. So make sure that you use this feature only on correct responses. An incorrect response for a test points to some bug on your code. So you'll need to fix that before you'll be able to generate assertions using this feature.