DPR302: Behavior Driven Development in the Real World - MSDN

gayheadtibburInternet and Web Development

Feb 5, 2013 (4 years and 7 months ago)

151 views

starr@pluralsight.com

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

As a

I want

So that

Given

When

Then


Given


When


Then

[
TestMethod
]

public
void

Total_Should_Be_1_When_1_Product_Added
()

{



var
cart = new
ShoppingCart
(
"TEST");





cart.AddItem
(
new
Product(
"SKU"));





Assert.AreEqual
(1
,
cart.TotalItems
);


}

Establish
Initial Context

Given

Arrange

SetContext

Interact with
SUT

When

Act

BecauseOf

Check the
results

Then

Assert

ItShould

Final Test

Shared
Context

Create an empty
cart

Add a Product
and check
SubTotal

Add 2 Products
and check
SubTotal

Final Test

Inherited
Context

Base
Context

Add Product to
Cart

Add another of
same Product

Check Cart
Subtotal

Check Cart
Item Count

Add a different
Product

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 31
st

http://
northamerica.msteched.com/registration



You can also register at the

North
America 2011
kiosk
located at
registration

Join us in Atlanta next year