Building robust test coverage for your APIs can take time. With the Test Creation Agent, you can accelerate this process.
This article explains how to create an API test with GenAI:
- Define the intent of the test
- Add information about the API under test
- Launch the API Test Editor
- Build out the test
The Test Creation Agent was formerly known as GenAI Test Creation.
Define the intent of the test
When you create a new API test, add a description of what you want the test to accomplish using natural language. mabl’s AI will generate test steps to carry out this intent.
For guidelines on how to write an effective test prompt, click here.
Providing a test prompt
When you add a test intent, a new API specification section appears on the test creation form. Use this section to add information about the API under test.
Add information about the API under test
To generate API test steps, mabl needs to know what API endpoints are available to interact with and how to interact with them. In the API specification section, upload files and/or provide an API description.
Upload a file
For best results, we recommend uploading a specification that includes full details on endpoints, supported content types, and the structure of request and response objects. Examples include OpenAPI specs (sometimes referred to as Swagger specs) or GraphQL schemas.
In the absence of a single standardized API spec, you can try uploading other files that contain similar information, such as a Postman collection, code files, sample request and response objects, HAR logs captured by Chrome DevTools, or even a text description.
Provide an API description
The API description can include any information that isn’t captured in uploaded files or any details that are more convenient to write as text than to upload as file, such as authentication instructions, requirements for headers, or a sample cURL request and response for an endpoint that you want to test.
Launch the API Test Editor
After describing the intent of the test and providing the API specification, fill out the remaining information on the test creation form and click on Create test.
When the API Test Editor launches, mabl’s AI uses the test intent and API specification to generate your test. The Test Creation Agent will search for an import API flows from your workspace if they are relevant to the test intent. Tasks break down the overall intent of the test into smaller goals.
If you’re satisfied with the preview, click on Create test to load the generated steps and build out the test.
If you’re looking for something different, modify the test intent and click on Generate new outline.
Build out the test
Review each step in the test and make adjustments as needed. Steps created with the Test Creation Agent can include the following:
- Step name
- URL
- Method
- Headers
- Request body
- Assertions
- Variables
In imported flows, the Test Creation Agent can use the default parameter values or override those defaults to better fit the test intent if needed.
Run the steps in the API Test Editor to validate whether everything works as expected and update as needed.
Limitations
- mabl uses generative AI to generate your API test steps, and is limited by the information provided. There may be mistakes in generated steps if insufficient information is provided on the API, or if the schema is too complex for mabl to interact with.
- Generated API test steps do not include snippets, so more complex validations or pre-request and post-request scripts will not be created.
- The OAuth 1.0 and OAuth 2.0 auth types will not be generated. If you want to authenticate to your API using one of these methods, you can generate the test and manually add the auth settings on the test level.
- The Test Creation Agent is biased towards English. If you define the test intent in a non-English language, the API Test Editor may still generate tasks and assertions in English.