Skip to content

This framework demonstrates how to perform assertions on PostgreSQL database state using Reqnroll DataTable.

Notifications You must be signed in to change notification settings

Suban5/PostgreSQL-Reqnroll-Assertions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PostgreSQL-Reqnroll-Assertions

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.

Description

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.

Interesting Techniques

  • Centralized Data Filtering:
    Support/Extensions/DataTableHelper.cs normalizes test data, converting "null" strings to actual null values 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.

Notable Libraries and Technologies

  • Reqnroll — BDD for .NET, Gherkin support.
  • Dapper — Lightweight ORM for .NET.
  • NUnit — Unit testing framework.
  • Npgsql — PostgreSQL driver for .NET.

Project Structure

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 .feature files 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.

How to Use

  1. Set up the database:

    • Create database in PostgreSql
    • Run the SQL in Scripts/createTable.txt to create the required tables in your PostgreSQL instance.
    • Run the SQL in Scripts/insertData.txt to insert any initial or sample data needed for your tests.
  2. Configure the connection:

    • Open your appsettings.json file.
    • Update the database name and PostgreSQL password in the connection string to match your environment.
  3. Build and run the tests:

    • The project already includes Gherkin scenarios in the Features/ directory.
    • Use your preferred test runner (e.g., dotnet test or the test explorer in your IDE) to build and execute the tests directly.
  4. Extend as needed:

Quickstart

  1. Clone the repository:
    git clone https://github.com/yourusername/PostgreSQL-Reqnroll-Assertions.git
    cd PostgreSQL-Reqnroll-Assertions

External Resources


For questions or contributions, please open an issue or pull request.

About

This framework demonstrates how to perform assertions on PostgreSQL database state using Reqnroll DataTable.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published