1 / 16

ASP.NET MVC, TDD, and Mock Objects

ASP.NET MVC, TDD, and Mock Objects. Josh Gough ATL ALT.NET dotnet.meetup.com/134. Sept 24, 2008: Agenda. 07:00 - 08:00: Dinner, drinks, and open discussion 08:00 - 09:30: Focused discussion: 30 min MVC+TDD+Mock Objects demo; 60 min group discussion on MVC, TDD & Mock Objects.

Download Presentation

ASP.NET MVC, TDD, and Mock Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET MVC, TDD, and Mock Objects Josh Gough ATL ALT.NET dotnet.meetup.com/134

  2. Sept 24, 2008: Agenda • 07:00 - 08:00: Dinner, drinks, and open discussion • 08:00 - 09:30: Focused discussion: 30 min MVC+TDD+Mock Objects demo; • 60 min group discussion on MVC, TDD & Mock Objects

  3. About ATL ALT.NET We are a community of developers in Atlanta dedicated to helping each other learn and apply the best of .NET technologies. Based on the “ALT.NET” groups from http://altnetpedia.com • Calendar: http://dotnet.meetup.com/134 • Wiki: http://atlalt.net/screwturn/

  4. ASP.NET Model-View-Controller (MVC) • Much like Ruby-on-Rails, other MVC frameworks From www.asp.net/mvc: • Clear separation of concerns(Clean code model, loose coupling, high cohesion) • Testability - support for Test-Driven Development (And easy to mock dependencies) • Fine-grained control over HTML and JavaScript(works well with async and ajax) • Intuitive URLs(excellent for SEO, strong-naming of URLs)

  5. Test-Driven-Development From http://en.wikipedia.org/wiki/Test-driven_development • Requirement identified • Write an automated test • Run tests and make sure new one FAILS • Write some code • Run tests to make sure all PASS • Refactor • Repeat

  6. TDD: • Unit Test Frameworks for .NET: • NUnit • Visual Studio Test Framework • MbUnit • Pex

  7. Goals of Test Automation: xunitpatterns.com

  8. Browser and Acceptance Test Frameworks • Selenium • WatiN • FitNesse for .NET • Others?

  9. Mock Objects From http://en.wikipedia.org/wiki/Mock_object In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways.

  10. Good examples of using Mocks: • supplies non-deterministic results (e.g. the current time or temperature); • has states that are difficult to create or reproduce (e.g. a network error); • slow (e.g. a database which would have to be initialized before the test); • does not yet exist or may change behavior; • would have to include information and methods exclusively for testing purposes

  11. .NET Mocking Frameworks From Roy Osherove’s blog: • Rhino Mocks • Moq • NMock • EasyMock • TypeMock

  12. Popularity of MockingFrameworks

  13. Simple Demo: MVC File Processor Simple, not complete, but demonstrates: • NUnit Unit Test Suite • Mocked Http File Upload (credit: Scott Hanselman for this code) • MvcContrib SimplyRestful Routing Extension • Some adherence to SOLID design principles • Thanks for Chris Rauber, Kevin Skibbe for design ideas here, and Brian McCafferty for the S#arp architecture http://code.google.com/p/sharp-architecture/

  14. SimplyRestful Routing Automatically maps controllers to 8 standard “RESTful” routes. Keeps application focused on nouns instead of verbs/actions. Part of MvcContrib.org. Learn more at: http://abombss.com/blog/2007/12/10/ms-mvc-simply-restful-routing/ public static void RegisterRoutes(RouteCollection routes) { SimplyRestfulRouteHandler.BuildRoutes(routes); }

  15. SimplyRestful Routes

  16. Conclusion Thanks! Questions, Comments, Tips? • Learn more about ASP.NET MVC at http://www.asp.net/mvc • Notes about tonight will be on http://atlalt.net/screwturn • Completed demo solution sample will be posted on http://dotnet.meetup.com/134

More Related