Skip to content

Creating a high level test

Tom Longhurst edited this page Apr 27, 2020 · 1 revision

Tests can be constructed either by extending from a base class (recommended for cleaner and more readable tests), or by using the test builder object.

Extending from BDTestBase

public class MyTests : BDTestBase
{
    [Test]
    public void Test1() {
        Given(() => Action1())
        .When(() => Action2())
        .Then(() => Action3())
        .BDTest();
    }
}

Or by using the BDTestBuilder object

public class MyTests 
{
    [Test]
    public void Test1() {
        new BDTestBuilder().Given(() => Action1())
                            .When(() => Action2())
                            .Then(() => Action3())
                            .BDTest();
    }
}

Best Practice

BDTest enforces best practice:

  • Tests MUST contain

    • Given + When + Then and executed with a BDTest(Async)
    • OR
    • When + Then and executed with a BDTest(Async)

    The former would be when a test needs setup to get to the required state. The latter if no state is required.

  • Tests MUST start with a Given or a When

    • Off of a Given you can have And or When
      • Off of an And you can have And or When
    • Off of a When you can have a Then
      • (No And - We should be testing one action!)
    • Off of a Then you can have And or BDTest(Async)
      • Off of an And you can have And or BDTest(Async)
Clone this wiki locally