Last active
October 17, 2017 20:08
-
-
Save sverrehundeide/7e2400f1b17f18030a83a6aa80df61a9 to your computer and use it in GitHub Desktop.
Blog - A simple and compact style for BDD specifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void $Method$_Given$Context$_Should$ExpectedBehaviour$() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void $Method$_Given$Context$_Should$ExpectedBehaviour$() | |
{ | |
//Arrange | |
$body$ | |
//Act | |
//Assert | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read full blog post at https://blog.hundeide.net/2009/06/a-simple-and-compact-style-for-bdd-specifications/