Ensure.Generator 0.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global Ensure.Generator --version 0.2.1
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local Ensure.Generator --version 0.2.1
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Ensure.Generator&version=0.2.1
                    
nuke :add-package Ensure.Generator --version 0.2.1
                    

Ensure.Generator

A .NET tool for generating test code from specification files.

NuGet NuGet License .NET

Inspired by SpecFlow and Gauge, but with a focus on simplicity and modern .NET features. While SpecFlow and Gauge are full-featured BDD frameworks, Ensure.Generator takes a lightweight approach by focusing solely on generating clean, typed test code from markdown specifications.

Why Executable Specifications?

In today's rapidly evolving software landscape, acceptance tests and executable specifications are becoming increasingly crucial. They serve as living documentation that evolves with your codebase, ensuring that your tests always reflect the current business requirements. Learn more about why this approach is gaining traction in this detailed overview video.

Installation

dotnet tool install --global Ensure.Generator

Usage

  1. Create a specification file (e.g., example.spec.md) in your test project
  2. Run the generator:
ensure -s path/to/specs -o path/to/output -n namespace

Examples

Scenario-Based Tests

# User Authentication

* Navigate to "login" page
* Clear browser cookies
* Initialize test database

## User can login successfully
* Enter username "john.doe@example.com"
* Enter password "securePass123"
* Click login button
* Verify user is redirected to "dashboard"
* Verify welcome message shows "Welcome, John Doe"

Table-Driven Tests

# User Data Validation

## Validate Multiple Users

* When I validate multiple users data

| Name  | Age | Email           |
|-------|-----|-----------------|
| John  | 25  | john@email.com  |
| Alice | 30  | alice@email.com |

* Then all users should be valid

Generated Code

The tool generates both test classes and step definitions. Here's what the generated code looks like:

Generated Test Class

// <auto-generated />
public abstract class UserAuthenticationTestsBase
{
    protected abstract UserAuthenticationStepsBase Steps { get; }

    [Fact]
    public async Task UserCanLoginSuccessfully()
    {
        await Steps.NavigateToPage("login");
        await Steps.ClearBrowserCookies();
        await Steps.InitializeTestDatabase();
        await Steps.EnterUsername("john.doe@example.com");
        await Steps.EnterPassword("securePass123");
        await Steps.ClickLoginButton();
        await Steps.VerifyUserIsRedirectedTo("dashboard");
        await Steps.VerifyWelcomeMessageShows("Welcome, John Doe");
    }
}

Generated Step Definitions

// <auto-generated />
public abstract class UserAuthenticationStepsBase
{
    /// <summary>
    /// Navigate to "login" page
    /// </summary>
    public abstract Task NavigateToPage(string param1);

    /// <summary>
    /// Enter username "john.doe@example.com"
    /// </summary>
    public abstract Task EnterUsername(string param1);

    // ... other step definitions
}

To implement the tests, create a concrete class that inherits from the generated base class and implements the step definitions:

public class UserAuthenticationTests : UserAuthenticationTestsBase
{
    protected override UserAuthenticationSteps Steps => new();
}

public class UserAuthenticationSteps : UserAuthenticationStepsBase
{
    public override async Task NavigateToPage(string page)
    {
        // Your implementation here
    }

    // Implement other steps...
}

Features

  • Generates test code from markdown specification files
  • Supports BDD-style specifications
  • Easy integration with existing test projects
  • Table-driven test scenarios
  • Scenario-based test cases
  • Common setup and teardown support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.4.3 766 2/23/2025
0.4.2 111 2/23/2025
0.4.1 123 2/23/2025
0.4.0 100 2/23/2025
0.3.2 110 1/31/2025
0.3.1 99 1/31/2025
0.3.0 106 1/31/2025
0.2.1 108 1/25/2025
0.2.0 109 1/25/2025
0.1.0 113 1/25/2025