Skip to content

Instantly share code, notes, and snippets.

@sverrehundeide
Last active October 17, 2017 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sverrehundeide/7e2400f1b17f18030a83a6aa80df61a9 to your computer and use it in GitHub Desktop.
Save sverrehundeide/7e2400f1b17f18030a83a6aa80df61a9 to your computer and use it in GitHub Desktop.
Blog - A simple and compact style for BDD specifications
public void $Method$_Given$Context$_Should$ExpectedBehaviour$()
[TestMethod]
public void $Method$_Given$Context$_Should$ExpectedBehaviour$()
{
//Arrange
$body$
//Act
//Assert
}
namespace BDDSimpleStyleExample
{
[TestClass]
public class DateTimeSpecifications
{
[TestMethod]
public void AddDays_GivenTodayIs1stOfJanuaryAndAddingTwoDays_ShouldReturnJanuary3rd()
{
//Arrange (setup up context / fixture, usually multiple lines of code)
var today = new DateTime(2009, 1, 1);
//Act (one line of code, invoke the System Under Test)
DateTime result = today.AddDays(2);
//Assert (Usually ONE assert / specification)
Assert.AreEqual(new DateTime(2009, 1, 3), result);
}
[TestMethod]
public void AddDays_GivenDateIsLastDayOfMonthAndAddingOneDay_ShouldReturnFirstDayOfNextMonths()
{
//Arrange
var today = new DateTime(2009, 1, 31);
//Act
DateTime result = today.AddDays(1);
//Assert
Assert.AreEqual(new DateTime(2009, 2, 1), result);
}
}
}
@sverrehundeide
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment