Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Like this? Share it with your network

Share

培育软件的可测试性

on

  • 8,497 views

Technical Track

Technical Track
From: 许晓斌

Statistics

Views

Total Views
8,497
Views on SlideShare
1,583
Embed Views
6,914

Actions

Likes
4
Downloads
61
Comments
1

16 Embeds 6,914

http://www.juvenxu.com 6840
http://zhuaxia.com 16
http://www.zhuaxia.com 13
http://ww.juvenxu.com 12
http://xianguo.com 11
http://cache.baidu.com 6
http://98.130.162.53 4
http://mvnbook.juvenxu.com 3
http://us-w1.rockmelt.com 2
http://translate.googleusercontent.com 1
http://jira.juvenxu.com 1
http://snapshot.soso.com 1
http://www.juvenxu.com. 1
http://www.juvenxu.com&_=1328330573218 HTTP 1
http://a0.twimg.com 1
http://www.xianguo.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • good slide,simple, clear
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

培育软件的可测试性 Presentation Transcript

  • 1. CultivateSoftware Testability Juven Xu Agile Tour Shanghai 2011
  • 2. Juven Xu 许晓 Twitter: @juvenxu Weibo: @Juvenxu juvenshun@gmail.comhttp://www.juvenxu.com/
  • 3. Why we discuss testability here?
  • 4. Why we discuss testability here?Because testing is expensive.
  • 5. Why we discuss testability here?Because testing is expensive.Because we want more tests.
  • 6. Why we discuss testability here?Because testing is expensive.Because we want more tests.Because testable software tends to be well designed.
  • 7. Why we discuss testability here?Because testing is expensive.Because we want more tests.Because testable software tends to be well designed.Because it’s a bond between developers and testers.
  • 8. Higher testability, higher quality
  • 9. Code Example
  • 10. public class Emailer { private SpellChecker spellChecker; public Emailer() { this.spellChecker = new EnglishSpellChecker(); } ...} Is there a way to test the interaction between Emailer and SpellChecker?
  • 11. public class Emailer { private SpellChecker spellChecker; public Emailer(SpellChecker spellChecker) { this.spellChecker = spellChecker; } ...}
  • 12. public class Emailer { private SpellChecker spellChecker; public Emailer(SpellChecker spellChecker) { this.spellChecker = spellChecker; } ... }public class EmailerTest { public class MockSpellChecker implements SpellChecker { @Test private boolean didCheckSpelling = false; public final void ensureSpellingWasChecked() { MockSpellChecker mock = new MockSpellChecker(); public boolean check(String text) { didCheckSpelling = true; new Emailer(mock).send(“Hello!”); return true; assert mock.verifyDidCheckSpelling() } : “failed to check spelling”; } public boolean verifyDidCheckSpelling() {} return didCheckSpelling; } }
  • 13. What we have done for testability?Allowed the test to control the construction of Emailer.Allowed the test to observe the behavior of the Emailer.
  • 14. IEEE defines testability as:“The degree to which a system or componentfacilitates the establishment of test criteria andthe performance of tests to determine weatherthese criteria have been met.”
  • 15. IEEE defines testability as:“The degree to which a system or componentfacilitates the establishment of test criteria andthe performance of tests to determine weatherthese criteria have been met.” “But what the hell does this mean?”
  • 16. In stead, can we think test as:1. Prepare the software to a state ready to be tested.2. Input test data.3. Observe the output.4. Compare the actual output to the expected output.
  • 17. Then, we define testability as: Control Visibility Knowledge
  • 18. Control,Visibility, and Knowledge
  • 19. I see what is testability and why it matters, but how to cultivate it?
  • 20. • Use Dependency Injection• Follow Single Responsibility Principle• Log Carefully• Manage Configuration• Prefer Conventional Interface
  • 21. “Most of the critical problemswith integration can be avoided if framework designers keep one fundamental principle in mind: testability” -- Dhanji R. Prasanna
  • 22. DI is about building the Object Graph.
  • 23. Dependency Injection• It gives you control• It provides you visibility• It implied good design
  • 24. Test It!
  • 25. Test It!
  • 26. Test It!Single Responsibility Principle
  • 27. Logging for Visibility
  • 28. Logging for Visibility• Don’t log too less, don’t log too much• What to log• Log Level
  • 29. Manage the Configuration• Separate configuration from runtime.• Keep it simple.• Make it easy to be changed.
  • 30. <?xml version=”1.0” encoding=”UTF-8”> <web-app> <servlet> <servlet-name>awesome_servlet</servlet-name> <description>Am I Awesome?</description> <servlet-class>com.awesome.AwesomeServlet</servlet-class> <init-param> <param-name>awesome-level</param-name> <param-value>super</param-value> </init-param> </servlet> <servlet-mapping> ... </web-app></xml> Looks familiar?
  • 31. Prefer Conventional Interface• Plain Text over Binary• HTTP over SOAP• Convention over Configuration
  • 32. References• Marc McDonald (2007). The Practical Guide to Defect Prevention. Microsoft Press• Bret Pettichord (2002). “Design for Testability”• Lesse Koskela (2007). Test Driven:TDD and Acceptance TDD for Java Developers. Manning Publications• Dhanji R. Prasanna (2009). Dependency Injection, Manning Publications• Jez Humble (2010). Continuous Delivery: Reliable Software Releases through Build,Test, and deployment Automation, Addison-Wesley Professional• Andrew Hunt (1999). The Pragmatic Programmer: From Journeyman to Master, Addison-Wesley Professional