Skip to content

✖ An xUnit.net extension for describing each step in a test with natural language.

License

Notifications You must be signed in to change notification settings

bbvch/LambdaTale

 
 

Repository files navigation

LambdaTale

LambdaTale NuGet version is a xUnit.net extension for describing each step in a test with natural language.

Note

This is a fork of xBehave.net. Adam, thank you very much!

CI CodeQL Lint Spell check

Platform support: .NET Standard 2.0 and upwards.

Usage

Install the bbv.LambdaTale NuGet package and start using LambdaTale in your tests. LambdaTale can be used in two different ways: Through a string extension method or a static Spec() method. Both usages are described below.

String Extension Method

An example of using LambdaTale with the x() extension method is given below.

using System.Threading.Tasks;
using LambdaTale;

namespace Your.Tests;

public class SomeFeature
{
    public class OracleService
    {
        public Task<int> Run() => Task.FromResult(42);
    }

    [Scenario]
    public void SimpleDemo(int answer, OracleService sut)
    {
        "Given a magic oracle"
            .x(() => sut = new OracleService());

        "the answer"
            .x(async () => answer = await sut.Run());

        "is always known"
            .x(() => Xunit.Assert.Equal(42, answer));
    }
}

Static Spec Method

An example of using LambdaTale with a C# 6.0 using static directive and the static Spec() method is given below.

using System.Threading.Tasks;
using LambdaTale;
using static LambdaTale.Specifications;

namespace Your.Tests;

public class SomeFeature
{
    public class OracleService
    {
        public Task<int> Run() => Task.FromResult(42);
    }

    [Scenario]
    public void SimpleDemo(int answer, OracleService sut)
    {
        Spec("Given a magic oracle", () => sut = new OracleService());

        Spec("the answer", async () => answer = await sut.Run());

        Spec("is always known", () => Xunit.Assert.Equal(42, answer));
    }
}

Gotchas

The ITestOutputHelper will only write to test steps. Messages written before the first step (e.g. in the constructor, [Background], outside step definitions) will be logged as part of the first step, messages written after the last step (e.g. inside Dispose) will be logged as part of the last step.

Packages

The LambdaTale package depends on the xunit.core package. That means you get only the minimum dependencies required to write and execute LambdaTale scenarios.

Versions

LambdaTale follows the versioning scheme of xUnit.net. xUnit.net and LambdaTale do not follow SemVer and may introduce breaking changes in minor (or even patch) versions. Each minor version of LambdaTale is linked to the equivalent minor version of xUnit.net. The LambdaTale patch version is incremented to the next multiple of 100 each time it is linked to a new xUnit.net patch version. For example, LambdaTale 2.5.0 is linked with xUnit.net 2.5.0, and LambdaTale 2.5.100 is linked with xUnit 2.5.1.

A given LambdaTale patch version may introduce new features, fix bugs, or both.

About

✖ An xUnit.net extension for describing each step in a test with natural language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.9%
  • Other 0.1%