Given -When-Then example with NUnit

epitka picture epitka · Oct 29, 2009 · Viewed 9.5k times · Source

Can anybody point me to some resources for Give-When-Then style of testing with NUnit?

Answer

Joseph picture Joseph · Oct 29, 2009

The Given When Then style correlates closely to the Arrange Act Assert style for unit testing.

Here's an example:

[Test]
public void RotateAngle_Given27Degress_Returns64Degrees()
{
   //Arrange or Given
   var someAngleClass = new Angle();

   //Act or When
   var result = someAngleClass.Rotate(27);

   //Assert or Then
   Assert.That(result, Is.EqualTo(64));
}

The great thing about this testing style is you don't need to see the underlying code to understand the intent of the behavior.

For more info here are some sites:

http://www.arrangeactassert.com/

Roy Osherove's Blog

http://www.artofunittesting.com/