-
Notifications
You must be signed in to change notification settings - Fork 0
Enabling Gherkin support
Romfos edited this page Feb 26, 2026
·
10 revisions
- Prerequisites. Setup BddDotNet project
- Add
BddDotNet.Gherkin.SourceGeneratornuget package
<PackageReference Include="BddDotNet.Gherkin.SourceGenerator" Version="2.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>- Add using directive with you assembly name to
Program.csfile - Use
SourceGeneratedGherkinScenariosandSourceGeneratedGherkinStepsextensions for configuration
Example:
Every time when you try to build your current project source generator will produce these method with content like this:
// <auto-generated/>
#nullable disable warnings
using BddDotNet;
using BddDotNet.Scenarios;
using Microsoft.Extensions.DependencyInjection;
namespace BddDotNet.Gherkin;
internal static partial class GherkinSourceGeneratorExtensions
{
public static partial void SourceGeneratedGherkinScenarios(this IServiceCollection services)
{
services.Scenario("DemoApp", "DemoApp", "Feature1", "demo scenario", """E:\dev\BDDNugetTest\BDDNugetTest\Features\Feature1.feature""", 6, async scenario =>
{
#line (7, 5) - (8, 1) 12 "E:\dev\BDDNugetTest\BDDNugetTest\Features\Feature1.feature"
await scenario.Given("""this is simple given step""");
#line (8, 5) - (9, 1) 12 "E:\dev\BDDNugetTest\BDDNugetTest\Features\Feature1.feature"
await scenario.When("""this is simple when step""");
#line (9, 5) - (10, 1) 12 "E:\dev\BDDNugetTest\BDDNugetTest\Features\Feature1.feature"
await scenario.Then("""this is simple then step""");
#line default
});
}
}// <auto-generated/>
#nullable disable warnings
using BddDotNet;
using BddDotNet.Steps;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace BddDotNet.Gherkin;
internal static partial class GherkinSourceGeneratorExtensions
{
public static partial void SourceGeneratedGherkinSteps(this IServiceCollection services)
{
services.TryAddScoped<global::DemoApp.Steps.Steps>();
services.Given(new("this is simple given step"), services => services.GetRequiredService<global::DemoApp.Steps.Steps>().Step1);
services.When(new("this is simple when step"), services => services.GetRequiredService<global::DemoApp.Steps.Steps>().Step2);
services.Then(new("this is simple then step"), services => services.GetRequiredService<global::DemoApp.Steps.Steps>().Step3);
}
}Setup
BddDotNet
Extensibility
Gherkin