Upload
edward-shields
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
DEV322Unit Testing Best Practices With Visual Studio 2005 Team System
Mark SeemannSenior ConsultantMicrosoft Consulting Services
Agenda
• What is a unit test?
• When to test?
• Who should test?
• How to test?
• What to test
• Choosing methodologies
• Best practices
Unit Testing Defined
• Tests a single assembly in isolation
• Volatile dependencies must be abstracted away
• Fully automated tests
• Unit tests constitute automated regression tests
• Binary results (pass or fail)
When To Write Unit Tests
• Before writing code
• Test-driven development, agile, XP, etc.
• After code is written
• Quality assurance, bug discovery, regression testing
Writing Unit Tests Before And After Writing Code
Mark Seemann
Senior Consultant
Microsoft Consulting Services
Who Should Write Unit Tests?
• Depends on the purpose of the test:
• Developers write their own tests in test-driven development
• Testers write quality assurance tests
• Developers should not write their own quality assurance tests
What To Test
• Unit test all of your own code, except
• User interfaces
• (Web) service façades
• UI and service façades should be subjected to other types of tests
• Test only against your public API
Pragmatic Unit Testing
• Usage-oriented
• Can involve sequences of operations
• Suitable for test-driven development
Formal Unit Testing
• Systematic
• Atomic
• Check boundary conditions
• Exercise error paths
• Suitable for QA
Atomic Unit Test Structure
1. Build initial state using alternative, low-level APIs if possible
2. Invoke test target member
3. Validate results
Best Practices
• Test cases must be independent
• Test cases must be deterministic
• Reproduce bugs as test cases
• Place tests in separate projects
• Have a test project per test target
• Use source control on test projects
Applying Best Practices with Visual Studio 2005 Team System
Mark Seemann
Senior Consultant
Microsoft Consulting Services
Resources
• Unit Testing Tips: Write Maintainable Unit Tests That Will Save You Time And Tears (http://msdn.microsoft.com/msdnmag/issues/06/01/UnitTesting)
• http://blogs.msdn.com/ploeh
Ask The ExpertsGet Your Questions Answered
You can find me at the Microsoft Ask the Experts area, located in the Exhibition Hall:
Friday 10 November 10.15 – 10.45