Ensure.Generator
0.2.1
See the version list below for details.
dotnet tool install --global Ensure.Generator --version 0.2.1
dotnet new tool-manifest
dotnet tool install --local Ensure.Generator --version 0.2.1
#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.
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
- Create a specification file (e.g.,
example.spec.md
) in your test project - 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 | Versions 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. |
This package has no dependencies.