7. Misko Hevery
Test Iceberg
www.danielteng.com
12年2月25日星期六
8. But, What is Unit Test
Anyway?
www.danielteng.com
12年2月25日星期六
9. A Test is NOT a Unit
Test If:
• It talks to the database
• It communicates across the network
• It touches the file system
• It can't run at the same time as any of your other
unit tests
• You have to do special things to your
environment (such as editing config files) to run it.
www.danielteng.com
12年2月25日星期六
10. I will do UT when I start
a green field project
• Legacy codebase
• UI is not testable
• It is QA’s job
• It doesn’t catch bug
• Too many dependencies
Real Reason change, I will have
• It double effort because when code
to change tests too.
I don’t know how to write!!!
www.danielteng.com
12年2月25日星期六
12. Test One Class
File DOC
System CPU
Intensive
Seam
Call
Dependency on
Component
DOC
Test Fixture Subject Under Test
Destructive
Dependency on
Assert
Component
Operations
DOC
Other
Dependency on Services
Component
Object Lifetime and Calling
Object Instantiated
Object Passed In
www.danielteng.com Revised from Misko Hevery
Global Object
12年2月25日星期六
14. Mixing Object
Constructions with Logic
Object graph Business Logic
constructions and
looking for
www.danielteng.com
12年2月25日星期六
15. Two Piles of Logic
• Construction logic • Business logic
• Factory
• Inversion of
Control
www.danielteng.com
12年2月25日星期六
16. Boy Scout Rule: “Leave the campground
cleaner than you found it.”
www.danielteng.com
12年2月25日星期六
17. Strategies Dealing with Legacy
• Build safe net by adding functional tests to
cover all business logic
• Move logic unit to its home and protect it
with tests
• Break dependencies by introducing seam
• Replace functional tests with unit tests
The Rule: FEEDBACK based on
Safe Steps
www.danielteng.com
SMALL
12年2月25日星期六
18. Now It is Up To YOU
www.danielteng.com
12年2月25日星期六
19. Now It is Up To YOU
www.danielteng.com
12年2月25日星期六