How can I set predefined examples for API test cases via the API?
To create test cases with example data already filled in using the API, first create the test with its column names, then add the data rows one by one.
Step 1. Create the test with its columns
Create the test and specify the column names for your data table. Send a POST request to /api/:project_id/tests with the following payload:
{ "data": { "type": "tests", "attributes": { "params": ["username", "password"] } }}paramsis an array of column header names for your data table.- The response will include the newly created test’s
id, keep it, you’ll need it next.
Step 2. Add one row of data
Add a single row of values. Send a POST request to /api/:project_id/examples:
{ "data": { "type": "examples", "attributes": { "test-id": "<id>", "data": ["admin", "secret123"] } }}test-idis the id from Step 1, it links this row to your test.datais an array of values. The order must match the order ofparamsfrom Step 1 (data[0]corresponds toparams[0], and so on). The first value goes under the first column, the second under the second, and so on. There are no names here, only the order matters.- Each call to
/api/:project_id/examplesadds one row.
Step 3. Repeat Step 2 for every row
Call /api/:project_id/examples again for each additional row you want.
You create the test’s structure once, then add the data rows one at a time, and your parameterized test ends up with all its examples.