Introduction to test_driven_development
Upcoming SlideShare
Loading in...5

Introduction to test_driven_development



This is the slides of my talk @ Taiwan Java User Group on 2011/07/09.

This is the slides of my talk @ Taiwan Java User Group on 2011/07/09.

You can watch the video here (in Chinese):



Total Views
Slideshare-icon Views on SlideShare
Embed Views



5 Embeds 84 67 8 5 3 1



Upload Details

Uploaded via as Adobe PDF

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.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Introduction to test_driven_development Introduction to test_driven_development Presentation Transcript

    • Introduction toTest-Driven Development Hao-Cheng Lee 本著作係依據創用 CC Attribution-ShareAlike 3.0 Unported 授權 條款進行授權。如欲瀏覽本授權條款之副本,請造訪 http: // ,或寄信至 Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA 。
    • About me● Hao-Cheng Lee● Java Engineer for 7+ years● Software Engineer @ Armorize● Interested in Java, Scala, TDD, CI● email:● twitter: haocheng● Google+: 浩誠
    • Download Java 7 RC Now Project Coin Slides
    • Agenda● What is TDD?● Why use TDD?● How to do TDD?● Pros and Cons● How do I start?
    • TDD = TFD +Refactoring
    • Not aboutwriting tests...
    • TDD is aboutwriting better code
    • from
    • Test Myths
    • I have no time for testing
    • Technical Debt from
    • My code isBUG-FREE!
    • from
    • QA will do the testing
    • Black Box Testing from
    • Fasterfrom
    • from Test Driven Development Tutorial by Kirrily Robert
    • Faster● Shorter release cycle● Automation saves time● Find bugs earlier
    • Betterfrom
    • Better● Greater code coverage● The courage to refactor● Prevent regression bugs● Improve your design
    • "Im not a great programmer;Im just a good programmerwith great habits." - Kent Beck
    • Testing the Old Way
    • TDD
    • TDD
    • How to do TDD?● Design: figure out what you want to do● Test: write a test to express the design ○ It should FAIL● Implement: write the code● Test again ○ It should PASS
    • DesignWe need a method add(), which takes two parameters and addthem together, then it will return the result.
    • Test
    • FAILjava.lang.AssertionError: expected:<2> but was:<0>
    • Implement
    • PASS
    • Write the least codeto make the test pass
    • More Test
    • FAILjava.lang.AssertionError: expected:<4> but was:<2>
    • Implement
    • PASS
    • DesignThe add() method only accept positive numbers
    • Test
    • FAILjava.lang.AssertionError: IllegalArgumentException expectedat
    • Implement
    • PASS
    • from
    • DesignWe need a addNewCustomer()method that will save a customer record in Database
    • Test
    • Test
    • FAILjava.lang.NullPointerExceptionat tw.idv.haocheng.CustomerDAOTest.addNewCustomer(
    • Implement
    • PASS
    • from
    • Design We hava a page that usercan apply for a new account
    • Test
    • Test
    • FAILwicket.markup.MarkupException: Unable to findcomponent with id accountFormPanel in[MarkupContainer ngc.account.wicket.edit.CreateAccountPageTest.setUp(
    • Implement
    • PASS
    • Unit Test Frameworks● Java - JUnit● Python - PyUnit● PHP - PHPUnit● Ruby - Test:Unit● Javascript - Jasmine● .Net - NUnit
    • Theres No Silver Bulletfrom
    • Costsfrom
    • It takes time...from
    • Need tomaintain tests
    • TDD is not suitable for... from
    • from
    • from
    • But how do I start??from
    • from
    • Suggestions● Prepare tools and environments● Learn to write Unit test● Start from easy ones
    • Reading List● The Bowling Game Kata● Unit Testing Guidelines● Why are we embarrassed to admit that we don’t know how to write tests? (中譯版本)● "The Clean Code Talks -- Unit Testing"● Top 10 things which make your code hard to test
    • References - Test-Driven Development● Test Driven Development Tutorial by Kirrily Robert● Engineer Notebook: An Extreme Programming Episode by Robert C. Martin and Robert S. Koss● Technical Debt by Martin Fowler● InfoQ: Testing Misconceptions by Liam OConnor● Unit Test Isolation● Erratic Test● Singletons are Evil● RSpec 讓你愛上寫測試