> 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-walnutai/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>
