ISABackendInstructions
EntityNonExistenceValidate
Validate database record non-existence
EntityNonExistenceValidate lets you verify that a record has been deleted from the database, commonly used for testing delete operations.
Basic Usage
Then should not exist a todo, with table:
| todoId | userId |
| $todo1.id | $Alice.id |This instruction will:
- Map "todo" to the
todostable via Entity Spec and retrieve field definitions - Use the provided fields as query conditions
- Validate the query result is empty (record does not exist)
Use Case
After a delete operation, confirm the record has been removed from the database:
When (UID="$Alice.id") delete todo, call table:
| P:todoId |
| $todo1.id |
Then delete todo(200) response, with table:
| message |
| Delete succeeded |
Then should not exist a todo, with table:
| todoId |
| $todo1.id |Mapping to Entity Spec
The EntityNonExistenceValidate instruction uses Entity Spec to map business entity names to actual database tables, and validates field existence against the DDL.
# entity_to_table_mapping.yml
entity_to_table_mapping:
- todo: todos
- user: users-- schema.sql
CREATE TABLE todos (
todo_id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
title VARCHAR(200) NOT NULL,
completed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Then should not exist a todo, with table:
| todoId |
| $todo1.id |
# SpecFormula automatically maps to the todos table
# SELECT * FROM todos WHERE todo_id = ?
# Validate query result is empty| Gherkin Element | Mapping Source |
|---|---|
todo | entity_to_table_mapping key |
todos table | entity_to_table_mapping value |
todoId field | DDL field definitions |
Lookup Strategies
PK Query (Priority)
Provide the complete primary key to query directly:
| todoId |
| $todo1.id |
# SELECT * FROM todos WHERE todo_id = ?
# Validate query result is emptyProbe Query
Use non-PK field combinations as query conditions:
| userId | title |
| $Alice.id | Buy milk |
# SELECT * FROM todos WHERE user_id = ? AND title = ?
# Validate query result is emptyLimitations
This instruction does not support:
- CAS constraint symbols (
&...) - VAR extraction keys (
>contextKey) - Response source fields (
<executionKey)
Error Handling
Lint Phase
| Error | Description |
|---|---|
| Entity not defined | Not found in entity_to_table_mapping |
| Field not found | Field not found in table definition |
| Unsupported symbol | CAS or VAR extraction syntax used |
Runtime
| Error | Description |
|---|---|
| Record still exists | Record expected to not exist actually exists |
| Missing query condition | No fields provided as query conditions |
Complete Example
Feature: Delete Todo
Background:
# EntitySetup instruction (see EntitySetup docs)
Given prepare a user, with table:
| >Alice.id | name | email | status |
| <userId | Alice | alice@example.com | ACTIVE |
Example: Delete a todo item
# ApiCall instruction (see ApiCall docs)
When (UID="$Alice.id") create todo, call table:
| >todo1.id | title |
| <todoId | Buy milk |
# ApiCall instruction — P: prefix for Path parameter
When (UID="$Alice.id") delete todo, call table:
| P:todoId |
| $todo1.id |
# ResponseValidate instruction (see ResponseValidate docs)
Then delete todo(200) response, with table:
| message |
| Delete succeeded |
# EntityNonExistenceValidate instruction — verify record deleted
And should not exist a todo, with table:
| todoId | userId |
| $todo1.id | $Alice.id |