This tutioral walksthrough the process of creating an MVC.NET application using the principles of Test-Driven-Development.
- Create New ASP.NET MVC 4 empty project with unit test project
- Using NuGet add the folowing projects to the unit test project
- Selenium.Webdriver
- Selenium.Support
- Create base class for functional tests
- Create base class for pages for tests
- User Story:
- As a visitor to the site, I expect to see a greeting on the index page
This would translate into a functional test script as follows:
- Navigate to index page of application
- Locate "Hello, World!" on the web page
- Create functional test
- Run tests (it will fail)
- Create unit test for controller (this will require stub implementation)
- Run Tests (it will fail)
- Implement controller
- Run Tests (functional test will still fail)
- Implement view
- Run Tests (all pass)
Congratulations you have completed your user story.
- User Story:
- As a visitor, I want to be able to add 2 numbers and see the result
This would translate into a functional test script as follows:
-
Navigate to addition page of application
-
Enter 1 into the first box
-
Enter 1 into the second box
-
Click "=" button
-
Verify the result is 2
Note: This test should be repeated with various combinations of numbers.
- Create data driven functional test, including page
- Run tests (it will fail)
- Create data driven unit test for controller (this will require stub implementation)
- Run Tests (it will fail)
- Implement controller
- Run Tests (functional test will still fail)
- Implement view
- Run Tests (all pass)
Congratulations you have completed your user story.