This project is a BDD-style test automation framework for PostgreSQL-backed applications. It uses Reqnroll (a SpecFlow fork), Dapper, and NUnit to help developers and QA write clear, maintainable database tests using Gherkin feature files.
This framework demonstrates how to perform assertions on PostgreSQL database state using Reqnroll DataTable. It shows how to set up, insert, and verify data in database tables directly from Gherkin scenarios with reusable step definitions. The goal is to make it easy for both developers and QA to validate data-driven workflows in a straightforward, maintainable way.
- Centralized Data Filtering:
Support/Extensions/DataTableHelper.csnormalizes test data, converting"null"strings to actualnullvalues and replacing~with spaces. - Bulk Insert with Dapper:
Uses Dapper for efficient, parameterized bulk inserts, making test setup fast even with large datasets. - Dynamic SQL Generation:
WHERE clauses are built dynamically from table data, supporting flexible positive and negative assertions. - Generic Step Definitions:
Steps are written to work with any table and column set, reducing duplication and making the framework easy to extend.
- Reqnroll — BDD for .NET, Gherkin support.
- Dapper — Lightweight ORM for .NET.
- NUnit — Unit testing framework.
- Npgsql — PostgreSQL driver for .NET.
ReqnrollDbTest/
├── Features/ # Gherkin feature files (.feature)
├── StepDefinitions/ # Reqnroll step definitions - Maps Gherkin steps to code
├── Support/ # Supporting infrastructure and utilities
│ ├── Configuration/ # Configuration files
│ ├── Database/ # Database connection and query logic
│ ├── Extensions/ # Custom extensions (PostgreSqlDataHelper)
│ └── Models/ # Domain models/entities (POCO classes for database tables)
├── appsetting.json # Configure PostgresDb connection
└── scripts/ # Database scripts (SQL) (create Db, table and insert data)
- Features/: Gherkin
.featurefiles describing test scenarios in a human-readable format. - Scripts/: SQL scripts, such as
Scripts/createTable.txt, used for database schema setup or teardown. - StepDefinitions/: C# classes with methods that implement the Gherkin steps defined in feature files.
- Support/: Utilities and helpers.
- Support/Configuration/: Configuration-related helpers or files.
- Support/Database/: Database helpers for executing queries and bulk operations, e.g.,
Support/Database/PostgreSqlDataHelper.cs. - Support/Extensions/: Extension methods and helpers, e.g.,
Support/Extensions/DataTableHelper.cs. - Support/Models/: C# classes representing database entities.
-
Set up the database:
- Create database in PostgreSql
- Run the SQL in
Scripts/createTable.txtto create the required tables in your PostgreSQL instance. - Run the SQL in
Scripts/insertData.txtto insert any initial or sample data needed for your tests.
-
Configure the connection:
- Open your
appsettings.jsonfile. - Update the database name and PostgreSQL password in the connection string to match your environment.
- Open your
-
Build and run the tests:
- The project already includes Gherkin scenarios in the
Features/directory. - Use your preferred test runner (e.g.,
dotnet testor the test explorer in your IDE) to build and execute the tests directly.
- The project already includes Gherkin scenarios in the
-
Extend as needed:
- Add new feature files in
Features/, step definitions inStepDefinitions/, or models inSupport/Models/as your schema or scenarios grow.
- Add new feature files in
- Clone the repository:
git clone https://github.com/yourusername/PostgreSQL-Reqnroll-Assertions.git cd PostgreSQL-Reqnroll-Assertions
For questions or contributions, please open an issue or pull request.