In TDD there is Arrange Act Assert (AAA) syntax:
[Test]
public void Test_ReturnItemForRefund_ReturnsStockOfBlackSweatersAsTwo_WhenOneInStockAndOneIsReturned()
{
//Arrange
ShopStock shopStock = new ShopStock();
Item blackSweater = new Item("ID: 25");
shopStock.AddStock(blackSweater);
int expectedResult = 2;
Item blackSweaterToReturn = new Item("ID: 25");
//Act
shopStock.ReturnItemForRefund(blackSweaterToReturn);
int actualResult = shopStock.GetStock("ID: 25");
//Assert
Assert.AreEqual(expectedResult, actualResult);
}
In BDD writing tests uses a similar structure but with Given When Then (GWT) syntax:
[Given(@"a customer previously bought a black sweater from me")]
public void GivenACustomerPreviouslyBoughtABlackSweaterFromMe()
{ /* Code goes here */ }
[Given(@"I currently have three black sweaters left in stock")]
public void GivenICurrentlyHaveThreeBlackSweatersLeftInStock()
{ /* Code goes here */ }
[When(@"he returns the sweater for a refund")]
public void WhenHeReturnsTheSweaterForARefund()
{ /* Code goes here */ }
[Then(@"I should have four black sweaters in stock")]
public void ThenIShouldHaveFourBlackSweatersInStock()
{ /* Code goes here */ }
Although they are often considered the same there are differences. A few key ones are:
-
GWT can be mapped directly to the specification of a feature file in BDD frameworks
-
GWT is easier for non-developers to understand by encouraging use of plain English, and having a short description of what each part is doing
-
GWT are keywords in various BDD frameworks such as SpecFlow, and Cucumber
My question is are there any other differences (besides the names) between AAA and GWT? And is there any reason besides the ones specified above that one should be preferred over the other?
Aucun commentaire:
Enregistrer un commentaire