DPR302: Behavior Driven Development in the Real World

[email protected]
Blog: ElegantCode.com
@elegantcoder
As a
I want
So that
Given
When
Then
Story:
As a
I want
So I can
Scenario:
Given
When
Then the other Items are still in the Cart
And the Cart Item Count is correct
And the Cart Subtotal reflects the remaining Items
Given a searcher finds a recipe …
Given the button was clicked …
Given credit card is valid format …
Given credit card is charged …
Given the Name property is null …
Given the record exists …
As a
I want
So that
Given
When
Then
As a
I want
So that
[TestMethod]
public void
Total_Should_Be_1_When_1_Product_Added()
{
Given
var cart = new ShoppingCart("TEST");
When
cart.AddItem(new Product("SKU"));
Then
Assert.AreEqual(1, cart.TotalItems);
}
Establish
Initial Context
Interact with
SUT
Check the
results
Given
When
Then
Arrange
Act
Assert
SetContext
BecauseOf
ItShould
Shared
Context
Create an empty
cart
Final Test
Add a Product
and check
SubTotal
Add 2 Products
and check
SubTotal
Base
Context
Inherited
Context
Add another of
same Product
Add Product to
Cart
Add a different
Product
Final Test
Check Cart
Subtotal
Check Cart
Item Count
Check Cart
Subtotal
Check Cart
Item Count
= () =>
www.microsoft.com/teched
www.microsoft.com/learning
http://microsoft.com/technet
http://microsoft.com/msdn
Sign up for Tech·Ed 2011 and save $500
starting June 8 – June 31st
http://northamerica.msteched.com/registration
You can also register at the
North America 2011 kiosk located at registration
Join us in Atlanta next year