Skip to main content
Fixed up a couple of syntactic problems.
Source Link
Stephen
  • 146
  • 3

I like the BDD style test structure.

GivenAnObject WhenIPerformAnAction ThenIGetTheseResults

In C# this translates nicely to a namespace structure:

namespace GivenAnObject
{
  [TestFixture]
  class WhenIPerformAnAction
  {
    private MyObject result;

    [SetUp]
    public void GivenAnObject()
    {
      // CreateMyObject();
      WhenIPerformAnActionWhen();
    }

    public void WhenIPerformAnActionWhen()
    {
      result = MyObject.ExecuteAction();
    }

    [Test]
    public void ThenIGetAResult()
    {
      Assert.AreEqual(ExpectedResult, result);
    }
  }
}

When run in nunit tests that follow this paradigm will display very nicely as a well grouped set of tests which are testing the behaviour of the various parts of your program.

In your case these tests would be:

GivenADoor WhenTheDoorStartsWithV ThenTheDoorIsVirtual

GivenADoor WhenTheDoorDoesNotStartWithV ThenTheDoorIsNotVirtual

I like the BDD style test structure.

GivenAnObject WhenIPerformAnAction ThenIGetTheseResults

In C# this translates nicely to a namespace structure:

namespace GivenAnObject
{
  [TestFixture]
  class WhenIPerformAnAction
  {
    private MyObject result;

    [SetUp]
    public GivenAnObject()
    {
      // CreateMyObject();
      WhenIPerformAnAction();
    }

    public void WhenIPerformAnAction()
    {
      result = MyObject.ExecuteAction();
    }

    [Test]
    public void ThenIGetAResult()
    {
      Assert.AreEqual(ExpectedResult, result);
    }
  }
}

When run in nunit tests that follow this paradigm will display very nicely as a well grouped set of tests which are testing the behaviour of the various parts of your program.

In your case these tests would be:

GivenADoor WhenTheDoorStartsWithV ThenTheDoorIsVirtual

GivenADoor WhenTheDoorDoesNotStartWithV ThenTheDoorIsNotVirtual

I like the BDD style test structure.

GivenAnObject WhenIPerformAnAction ThenIGetTheseResults

In C# this translates nicely to a namespace structure:

namespace GivenAnObject
{
  [TestFixture]
  class WhenIPerformAnAction
  {
    private MyObject result;

    [SetUp]
    public void GivenAnObject()
    {
      // CreateMyObject();
      When();
    }

    public void When()
    {
      result = MyObject.ExecuteAction();
    }

    [Test]
    public void ThenIGetAResult()
    {
      Assert.AreEqual(ExpectedResult, result);
    }
  }
}

When run in nunit tests that follow this paradigm will display very nicely as a well grouped set of tests which are testing the behaviour of the various parts of your program.

In your case these tests would be:

GivenADoor WhenTheDoorStartsWithV ThenTheDoorIsVirtual

GivenADoor WhenTheDoorDoesNotStartWithV ThenTheDoorIsNotVirtual

Source Link
Stephen
  • 146
  • 3

I like the BDD style test structure.

GivenAnObject WhenIPerformAnAction ThenIGetTheseResults

In C# this translates nicely to a namespace structure:

namespace GivenAnObject
{
  [TestFixture]
  class WhenIPerformAnAction
  {
    private MyObject result;

    [SetUp]
    public GivenAnObject()
    {
      // CreateMyObject();
      WhenIPerformAnAction();
    }

    public void WhenIPerformAnAction()
    {
      result = MyObject.ExecuteAction();
    }

    [Test]
    public void ThenIGetAResult()
    {
      Assert.AreEqual(ExpectedResult, result);
    }
  }
}

When run in nunit tests that follow this paradigm will display very nicely as a well grouped set of tests which are testing the behaviour of the various parts of your program.

In your case these tests would be:

GivenADoor WhenTheDoorStartsWithV ThenTheDoorIsVirtual

GivenADoor WhenTheDoorDoesNotStartWithV ThenTheDoorIsNotVirtual