2. Who am I?
Test Engineer @ Red Gate Software
Based in Cambridge
MbUnit Core Commit Member
Actively involved with the project for past
18-24 months
NxtGenUG Member
Blog.BenHall.me.uk
3. Agenda
Unit Testing and Integration Testing
Demo
Tools and Frameworks
Database Layer
Business Layer
User Interface
MbUnit v3 and the Gallio Testing Platform
Summary
4. Unit Testing
Written by the developer
Focus on happy day scenarios
Ensures everything works as expected
Support change of inner workings
Support inexperience developers
Code is less of a black box
Manual testing is boring!
5. Integration Testing
We already have unit tests, why do we also
need integration tests?
Ideally written by a tester, however
generally written by a developer.
Unhappy scenarios
End-To-End scenarios
Does the code meet customer
requirements
6. MbUnit 2.4
www.MbUnit.com
Advanced testing framework
Open Source
Developed a number of years ago by Peli
(now works for Microsoft Research)
Actively developed by a core team of 15
8. Scenario
Core features of a e-commerce site
Users can view products, search and place
orders.
Linq to SQL for database access
ASP.net 2.0 for UI
Web service for payment processing
10. Business Layer
Demo
•Rhino Mocks to mock away from database
•Mocking external services
•RowTest
•Data Driven Tests
• MbUnit Asserts
•Custom Asserts
11. UI Testing
Don’t Automate!
At the moment its:
Hard work
Leads to fragile tests
No ‘good’ solution
There are solutions available...
12. WatiN - Web Application Testing
Demo
•Automate web application testing
•Supports Ajax
•Supports popups and logins.
•http://watin.sourceforge.net
13. UI Testing
Model View Controller – MVC
Ruby on Rails
MonoRail
ASP.net MVC
Model View Presenter – MVP
Difficult with WinForms/WPF
No other UI framework?
14. ASP.net MVC
Code Demo
•Released ‘Shortly’
•CTP as part of ASP.net Futures
•Alternative to WebForms – Not a
replacement
•Designed for testability
15. MbUnit v3
Alpha-1 release soon.
Based on the Gallio Testing Platform.
Goals
Improved documentation and support
Take testing to the next level
Accommodate more testing styles.
www.MbUnit.com
16. Gallio
Gallio is an open, extensible, and neutral
testing platform.
Supports multiple .Net test frameworks
including MbUnit, NUnit, NBehave, xUnit.Net
and others.
Share common components with community
More information on the wiki
http://code.google.com/p/mb-unit/
17. MbUnit v Nunit v MsTest v
XUnit
Whatever works best for you....
Nunit is simple and straightforward
MbUnit is powerful and versatile
MsTest – Don’t. Number of
problems, 2008 has a number of
improvements.
Xunit – New boy. Some nice ideas...
18. Resources
Books
xUnit Test Patterns – Gerard Meszaros
The Art of Unit Testing - Roy Osherove
Blogs
My blog - Blog.BenHall.me.uk
CodeBetter.com
Tools
MbUnit – www.MbUnit.com
TestDriven.Net – www.TestDriven.net
Rhino Mocks – www.Ayende.com
TypeMock – www.TypeMock.com
WatiN – http://watin.sourceforge.net
19. Summary
Keep things simple
Keep things small
Abstraction is key
ASP.net MVC is the future!
MbUnit v3 and Gallio are coming soon.
Thank you!
Slides + Code on my blog Blog.BenHall.me.uk
2 (2mins)Talk won’t be just on MbUnit, I will be touching on other tools such as Rhino Mocks which help improve testing. Find out how many people are unit testing at the moment? Who are using MbUnit?
7 (5mins)
10 (3mins)
15 (5mins)Sample\\SampleShort demo, covers what is the same with the three frameworks. How they can be executed, some of the cool tools to help. How Resharper can help when developing. Quick and too the point, make sure everyone is up to speed for the rest of the content.DemostrateMSTest, explain how it needs meta data and saves the results in TestResults.DemostrateNunit, show the asserts, how they are different from MSTest. Show how to run the tests using TD.net and ReSharper, show failing tests, Show Nunit UI. DemostrateMbUnit, show the assertions, show migrating from Nunit, show UI.Explain test layout, test naming, show ReSharper method template,
16 (1min)Show final application to show the end result so everything has a good idea where we are heading.
24 (8mins)Problems with Rollback/TransactionsNeed to ensure that you have a well known state for the database (demonstrate what happens if you don’t. Fragile tests).InternalsVisibleTo()ExplainLinq to SQL and each Repository (say why I have split it – to isolate and make tests more targetted).Explain that we use repositories so we can mock them as the DataContext cannot be mocked.Explain TestHelper (and Tests)InternalsVisibleTo() to hide some implementation but still have it tested. Hitting the database isn’t bad (just slow), the problems associated with databases is bad. Use TransactionsUse Rollback to make tests easierProblems with Rollback (Auto increment)Solution is DBCC (if auto increment is important to you) – Extract it into external script if you wish.
34 (10mins)Explain Mock ObjectsExplain why they are useful with external services (Payment)(ProductControllerTests)Refactor tests to include validation as that is also important to test. RowTest to enable range testing.Other\\DataDrivenTestsDemonstrate how it could be used. Show the class browser for MbUnit.FrameworkvsNunit to explain the different assertions we have. CustomerControllerTestsHowever, none meet our require. CustomAssert.AreEqual
36 (2mins)
40 (6mins)Show sample WatiN site, explain how it all works. Explain problems with UAC.
42 (2mins)
48 (4mins)ScottHa’sBlogEngine Code.Can’t be demo’ed as it won’t have been released.Explain how it all links together.View is very thin.