• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

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!

培育软件的可测试性

on

  • 8,399 views

Technical Track

Technical Track
From: 许晓斌

Statistics

Views

Total Views
8,399
Views on SlideShare
1,492
Embed Views
6,907

Actions

Likes
4
Downloads
61
Comments
1

16 Embeds 6,907

http://www.juvenxu.com 6833
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

11 of 1 previous next

  • 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

  • CultivateSoftware Testability Juven Xu Agile Tour Shanghai 2011
  • Juven Xu 许晓 Twitter: @juvenxu Weibo: @Juvenxu juvenshun@gmail.comhttp://www.juvenxu.com/
  • Why we discuss testability here?
  • Why we discuss testability here?Because testing is expensive.
  • Why we discuss testability here?Because testing is expensive.Because we want more tests.
  • Why we discuss testability here?Because testing is expensive.Because we want more tests.Because testable software tends to be well designed.
  • 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.
  • Higher testability, higher quality
  • Code Example
  • public class Emailer { private SpellChecker spellChecker; public Emailer() { this.spellChecker = new EnglishSpellChecker(); } ...} Is there a way to test the interaction between Emailer and SpellChecker?
  • public class Emailer { private SpellChecker spellChecker; public Emailer(SpellChecker spellChecker) { this.spellChecker = spellChecker; } ...}
  • 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; } }
  • 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.
  • 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.”
  • 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?”
  • 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.
  • Then, we define testability as: Control Visibility Knowledge
  • Control,Visibility, and Knowledge
  • I see what is testability and why it matters, but how to cultivate it?
  • • Use Dependency Injection• Follow Single Responsibility Principle• Log Carefully• Manage Configuration• Prefer Conventional Interface
  • “Most of the critical problemswith integration can be avoided if framework designers keep one fundamental principle in mind: testability” -- Dhanji R. Prasanna
  • DI is about building the Object Graph.
  • Dependency Injection• It gives you control• It provides you visibility• It implied good design
  • Test It!
  • Test It!
  • Test It!Single Responsibility Principle
  • Logging for Visibility
  • Logging for Visibility• Don’t log too less, don’t log too much• What to log• Log Level
  • Manage the Configuration• Separate configuration from runtime.• Keep it simple.• Make it easy to be changed.
  • <?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?
  • Prefer Conventional Interface• Plain Text over Binary• HTTP over SOAP• Convention over Configuration
  • 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