> For the complete documentation index, see [llms.txt](https://docs.walnutai.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.walnutai.ai/test-and-quality-management/test-management/creating-test-cases-in-walnut/how-to-create-db-test-case.md).

# How to create DB test case

A Database Test Case is a structured validation scenario designed to verify data integrity, data accuracy, and backend database operations.

* It connects to a configured database.
* Executes SQL queries or operations.
* Validates returned results to ensure correct data storage and retrieval.

#### **Steps to Create a DataBase Test Case**

* Click "[**Create New Test Case**](/test-and-quality-management/test-management/test-cases/test-case-creation.md)**"** to start a new validation scenario.
* Click **Add Step**, type “/” inside the step field.
  * From the dropdown, choose "**Test Case Type"**.
  * Select "**Database"** to configure structured DB validation steps without writing manual automation code.
* Select the required **Database Type**.
  * MySQL
  * PostgreSQL
  * MSSQL
  * MongoDB
* Configure the database connection using either:
  * Standard connection fields:
    * Host
    * Port
    * Database Name
    * Username
    * Password
    * Optional SSL toggle
  * OR enable "**Connection String"** toggle and paste the full connection string.
* Click "**Connect"** to establish the database connection.
  * Optionally click **Save Connection** to reuse it in future test cases.
* Under **Operation**, choose the required option (e.g., Custom).
  * Enter the SQL query in the query editor.
  * Or describe the query in plain English and click **Generate Query** to auto-generate SQL.
* Click "**Run Query"** to execute the query and view results.
* Use the available tabs for validation:
  * **Results**
    * View query execution output.
    * Verify returned records.
  * **Assertions**
    * Validate row count.
    * Verify specific column values.
    * Check data types.
    * Ensure fields are not null.
  * **Extract**
    * Capture values from query results.
    * Store values for reuse in later steps.
  * **Test Data**
    * Manage datasets for parameterized execution.
* You can use variables inside queries:
  * Global Variables → Type `$(`
  * Local Variables → Type `${`
  * Runtime Variables → Type `$[`
* To reuse an existing variables:
  * Type `${` and select the required variable from the dropdown.
* Enter the step description in simple English to clearly describe the database validation scenario.
  * Example: “Verify active users are returned from users table.”
  * Example: “Validate user record is inserted successfully.”
* Once configuration is complete, click **Save** to store the test case.
* Run the created DB test case using:
  * **Manual Mode**
    * Execute step-by-step validation.
  * **Automation (WalnutAI) Mode**
    * Automatically connects to database.
    * Executes queries.
    * Resolves variables and parameters.
    * Performs assertions.
    * Extracts values.
    * Generates structured execution results.
* For more details on execution flow and intelligent handling of changes, refer to the documentation on [**Execution & AI Healing**.](/test-and-quality-management/test-management/execution-and-ai-healing.md)<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.walnutai.ai/test-and-quality-management/test-management/creating-test-cases-in-walnut/how-to-create-db-test-case.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
