-
Notifications
You must be signed in to change notification settings - Fork 3
Given When Then
amirci edited this page Mar 7, 2011
·
2 revisions
Given, When, Then is a style of writing scenarios, borrowed from BDD tools like Cucumber.
Here is an example of the usage in Cucumber describing a scenario for a web application that works with movies:
Scenario: List the movies
Given I have the movies "Blazing Saddles" and "Young Frankenstein"
When I go to "list movies" page
Then I should see "Blazing Saddles" and "Young Frankenstein" in the listingWhen applied to unit tests, if you are familiar with the AAA style (Arrange, Act, Assert) GWT is very similar:
- Given = Arrange
- Act = When
- Assert = Then
Though I like AAA, I wanted a way to enforce how the scenarios should be written, that's why the MT Testing library enforces GWT syntax.
Because each framework usually has hooks before and after all the tests is very easy to implement the GWT syntax and call the Given and When methods. Here is a simplified version of the code to show how it's done:
protected override void BeforeEachTest()
{
this.GivenThat();
this.WhenIRun();
}