Download presentation
Presentation is loading. Please wait.
Published byEdward Shields Modified over 9 years ago
1
DEV322 Unit Testing Best Practices With Visual Studio 2005 Team System Mark Seemann Senior Consultant Microsoft Consulting Services
2
Agenda What is a unit test? When to test? Who should test? How to test? What to test Choosing methodologies Best practices
3
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)
4
When To Write Unit Tests Before writing code Test-driven development, agile, XP, etc. After code is written Quality assurance, bug discovery, regression testing
5
Writing Unit Tests Before And After Writing Code Mark Seemann Senior Consultant Microsoft Consulting Services
6
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
7
How To Write Tests What to test Choosing methodologies Best practices
8
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
9
Testing Against Public Only API Mark Seemann Senior Consultant Microsoft Consulting Services
10
Approaches Pragmatic Formal Approaches can be mixed
11
Pragmatic Unit Testing Usage-oriented Can involve sequences of operations Suitable for test-driven development
12
Writing a Pragmatic Unit Test Mark Seemann Senior Consultant Microsoft Consulting Services
13
Formal Unit Testing Systematic Atomic Check boundary conditions Exercise error paths Suitable for QA
14
Atomic Unit Test Structure 1. Build initial state using alternative, low-level APIs if possible 2. Invoke test target member 3. Validate results
15
Writing a Formal Unit Test Mark Seemann Senior Consultant Microsoft Consulting Services
16
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
17
Applying Best Practices with Visual Studio 2005 Team System Mark Seemann Senior Consultant Microsoft Consulting Services
18
Summary Unit test all relevant libraries Test only public API Set high code coverage goal
19
Resources Unit Testing Tips: Write Maintainable Unit Tests That Will Save You Time And Tears (http://msdn.microsoft.com/msdnmag/issues/06/01/UnitT esting)http://msdn.microsoft.com/msdnmag/issues/06/01/UnitT esting http://blogs.msdn.com/ploeh
21
Ask The Experts Get Your Questions Answered You can find me at the Microsoft Ask the Experts area, located in the Exhibition Hall: Friday10 November10.15 – 10.45
24
©2006 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.