220 likes | 354 Views
Test-Driving ASP.NET Development. Tampa Code Camp – July 15 th , 2006. Cory Foy foyc@cornetdesign.com http://www.cornetdesign.com. Test-Driving ASP.NET Development. Session Overview What’s this Agile/XP thing? What’s this Test-Driven Development thing? TDD/NUnit Bowling demo
E N D
Test-Driving ASP.NET Development Tampa Code Camp – July 15th, 2006 Cory Foy foyc@cornetdesign.com http://www.cornetdesign.com
Test-Driving ASP.NET Development • Session Overview • What’s this Agile/XP thing? • What’s this Test-Driven Development thing? • TDD/NUnit Bowling demo • Applying TDD to ASP.NET • Wrap-Up Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Extreme Programming • Base everything off four principles (the Agile manifesto): • Individuals and Interactions (over processes and tools) • Working Software (over comprehensive documentation) • Customer Collaboration (over contract negotiation) • Responding to change (over following a plan) Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Extreme Programming http://www.xprogramming.com/xpmag/whatisxp.htm Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Extreme Programming Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Extreme Programming Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Extreme Programming Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Test-Driven Development • It’s about coding • It’s about design • Way of developing applications by writing tests • Red-Green-Refactor • Write a failing test • Make the test pass by doing the simplest thing • Refactor duplication Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Test-Driven Development • NUnit (http://www.nunit.org) Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Write a test Test-Driven Development Watch it fail Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Make the test pass Test-Driven Development • Refactor Duplication Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
TDD Bowling Demo • Create an app to track the score of a bowling game • Consists of 10 frames which can be open frames, strikes, spares or bonus rolls • Scoring is different based on what the type of frame is Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Applying TDD to ASP.NET • NUnitAsp • http://nunitasp.sourceforge.net • Extension to NUnit • Originally created by Brian Knowles, now maintained by Jim Shore • Provides NUnit with the ability to download, parse and manipulate ASP.NET pages • Meant for programmers, not QA teams Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Applying TDD to ASP.NET Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Applying TDD to ASP.NET • NUnitAsp Drawbacks • Tests are slow because we are making actual requests to IIS • Information that isn’t sent to the client can’t be tested • Session and Cache values can’t be tested directly Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Applying TDD to ASP.NET • Model-View-Presenter • http://www.martinfowler.com/eaaDev/ModelViewPresenter.html • Separates the behavior of a presentation from the view while allowing the view to receive user events. • Make the page as “thin” as possible and extract the logic out to testable classes Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Applying TDD to ASP.NET • Extract the services you want to provide to an interface • Have your views implement the interface • Have all interactions between the view and controller be through interface exposed methods Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Applying TDD to ASP.NET Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06 http://www.martinfowler.com/eaaDev/ModelViewPresenter.html
Applying TDD to ASP.NET • ASP.NET MVP demo Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Applying TDD to ASP.NET • Advantages of Model-View-Presenter in TDD • Separates your logic from your presentation • Let’s your business logic be tested – fast • Allows mocks of the pages to be built to test user behavior • Easily allows additional views to be plugged in Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Wrap-Up • Do nothing without frequent feedback • Testing GUIs is hard – but can be mitigated • Try to make GUI tests (and GUIs) as thin as possible Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06
Wrap-Up • Links • http://msdn.microsoft.com/library/en-us/dnvs05/html/guidelinesfortdd.asp • http://www.testdriven.com • http://www.nunit.org • http://www.testdriven.net(VS plugin) • http://nunitasp.sourceforge.net • http://www.cornetdesign.com(presentation) Test-Driving ASP.NET Development Tampa Code Camp, 7/15/06