2. London based ASP.net MVPWeb Developer @ 7digital.com Open Source Developer WHO AM I? Co-Author Testing ASP.net Web Applications www.testingaspnet.com
23. Each test should add something to explain the behaviour of the class under test As you read down then it should continue to add more information in a logical way Structure
24.
25.
26. Bad structure Method1_does_this Method2_does_this Method2_does_something_else Method1_does_not_do_this EXAMPLE
27. Bad structure Method1_does_this Method1_does_not_do_this Method2_does_this Method2_does_something_else EXAMPLE
29. Naming of test Implementation I follow a BDD style which explains the behaviour If your naming talks about implementation, then your likely to test implementation – this could change! Like comments, you don’t want the test naming to be out of sync with what the actual test is doing
31. Make sure the important details are easy to identify Hide the irrevent information to identify which bits are key Variable names can help with this varexpiredCreditCardDate = ... Highlight relevant data
32. Duplicated Setup in test Use Setup Make test helpers which have pre-defined stub configs EXAMPLE
33. Duplicated Setup in test Use Setup Make test helpers which have pre-defined stub configs EXAMPLE
38. Scenario: Payment method has expired Given user John And John has expired credit card When I get the default payment method Then an invalid credit card will be returned Cuke4nuke SpecFlow
47. Mock Usage Not doing Unit Testing if you don’t use mocks Over usage ASP.net MVC is perfect example of having to do this Stubs return stubs returning stubs Too many mocks Mocking things you don’t own HttpContextBase IDbConnection
60. Design Smell Responsibilities of the class being tested Fixture talks about lots of different concepts Context Spec makes this a lot easier to identify Easier to see if structured correctly Smell - Responsibilities http://www.flickr.com/photos/ricmcarthur/56268640/
71. Scenario: Saving a product by name only Given the application has started And I enter the name "Product 1" When I save the product Then "Product 1" should be available to purchase
72. Given /^the application has started$/ do host = ApplicationLauncher.new @app = host.launch Dir.pwd + '/src/ExampleUIs/bin/Debug/ExampleUIs.exe' @main_window = @app.find_window 'petShopWindow' end Given /^I enter the name "([^quot;]*)"$/ do |product_name| textbox = @main_window.find_TextBox "petNameInput" textbox.text = product_name end When /^I save the product$/ do button = @main_window.find_Button "petSaveButton" button.click sleep(1) end Then /^"([^quot;]*)" should be available to purchase$/ do |product_name| combo = @main_window.find_ComboBox "basketInput" combo.Items.should include("Pet[#{product_name}]") end After do |scenario| @app.process.kill end
73. Full stack testing for ATDD? Waste of time! Feature coverage Can be used as part of a test metric
74. What’s good application design? When you read the code, it’s what you expect How quickly you can add tests How quickly you can implement new functionality Understandable by the team How much code churnework is being performed How much test coverage
75. Code Coverage Waste of time! Feature coverage Can be used as part of a test metric
76. Code and Test Reviews Better than metrics What the team thinks is good