`

Test Driven Development (TDD)

    博客分类:
  • Java
阅读更多
commend a method of Driven Development  : TDD

1. What is TDD?
The steps of test first development (TFD) are overviewed in the UML activity diagram of Figure 1.  The first step is to quickly add a test, basically just enough code to fail.  Next you run your tests, often the complete test suite although for sake of speed you may decide to run only a subset, to ensure that the new test does in fact fail.  You then update your functional code to make it pass the new tests.  The fourth step is to run your tests again.  If they fail you need to update your functional code and retest.  Once the tests pass the next step is to start over (you may first need to refactor any duplication out of your design as needed, turning TFD into TDD).



Figure 1. The Steps of test-first development (TFD).

I like to describe TDD with this simple formula:

   TDD = TFD + refactoring.

TDD completely turns traditional development around .Instead of writing functional code first and then your testing code as an afterthought, if you write it at all, you instead write your test code before your functional code.  Furthermore, you do so in very small steps – one test and a small bit of corresponding functional code at a time.  A programmer taking a TDD approach refuses to write a new function until there is first a test that fails because that function isn’t present.  In fact, they refuse to add even a single line of code until a test exists for it.  Once the test is in place they then do the work required to ensure that the test suite now passes (your new code may break several existing tests as well as the new one).  Once your code works, you then refactor it to ensure that it's remains of high quality.  This sounds simple in principle, but when you are first learning to take a TDD approach it proves require great discipline because it is easy to “slip” and write functional code without first writing a new test.  One of the advantages of pair programming (Williams and Kessler 2002) is that your pair helps you to stay on track.

An underlying assumption of TDD is that you have a unit-testing framework available to you.  Agile software developers often use the xUnit family of open source tools, such as JUnit or VBUnit, although commercial tools are also viable options.  Without such tools TDD is virtually impossible.  Figure 2 presents a UML state chart diagram for how people typically work with the xUnit tools.  This diagram was suggested to me by Keith Ray.

Figure 2. Testing via the xUnit Framework.


Kent Beck, who popularized TDD in eXtreme Programming (XP) (Beck 2000), defines two simple rules for TDD (Beck 2003).  First, you should write new business code only when an automated test has failed.  Second, you should eliminate any duplication that you find.  Beck explains how these two simple rules generate complex individual and group behavior:

You design organically, with the running code providing feedback between decisions.

You write your own tests because you can't wait 20 times per day for someone else to write them for you. 

Your development environment must provide rapid response to small changes (e.g you need a fast compiler and regression test suite).

Your designs must consist of highly cohesive, loosely coupled components (e.g. your design is highly normalized) to make testing easier (this also makes evolution and maintenance of your system easier too).

For developers, the implication is that they need to learn how to write effective unit tests.  Beck’s experience is that good unit tests:

Run fast (they have short setups, run times, and break downs).

Run in isolation (you should be able to reorder them).

Use data that makes them easy to read and to understand.

Use real data (e.g. copies of production data) when they need to.

Represent one step towards your overall goal.


2. TDD and Traditional Testing ...

3. TDD and Documentation ...

4. Test-Driven Database Development ...

5. TDD and Agile Model-Driven Development (AMDD) ...

6. Why TDD ...

7. Myths and Misconceptions ...

8. Summary ...

9. Tools ...

   ... ...

original text
分享到:
评论

相关推荐

    Test-Driven Development(TDD).pptx

    Test-Driven Development(TDD)简介,使用Nunit开发自动测试案例.

    Test Driven Development: By Example

    ### Test-Driven Development (TDD): By Example #### 引言 在软件开发领域,测试驱动开发(Test-Driven Development, TDD)是一种被广泛推崇的方法论,它提倡在编写实际代码之前先编写测试用例。这种方法不仅能...

    test.driven.tdd.and.acceptance.tdd.for.java.developers

    #### 二、测试驱动开发(Test-Driven Development, TDD) 测试驱动开发是一种软件开发流程,其基本步骤是:编写一个能够检测出期望功能是否完成的小测试,然后编写能够通过该测试的最小量代码,并重复这个过程。...

    iOS Test Driven Development by Tutorials

    iOS Test Driven Development by Tutorials FIRST EDITION, Learn real-world test-driven development PDF & EPUB & SourceCode

    Test Driven Development in Ruby:

    Test Driven Development in Ruby: A Practical Introduction to TDD Using Problem and Solution Domain Analysis by Bala Paranj English | 5 Apr. 2017 | ISBN: 1484226372 | 288 Pages | PDF | 5.32 MB Learn ...

    Test Driven Development, A J2EE example

    Test Driven Development: A J2EE Example by Russell Gold, Thomas Hammell and Tom Snyder ISBN:1590593278 Apress © 2005 (296 pages) Targeted at Java developers who want to learn how to use test-...

    Android Test Driven Development Tutorials - v1.zip

    在Android开发领域,Test Driven Development(TDD)是一种被广泛应用的编程实践,它强调先编写测试用例,再编写满足这些测试的代码。在这个"Android Test Driven Development Tutorials"资源包中,包含了PDF、ePub...

    Test-Driven Development with Python [2017]

    By taking you through the development of a real web application from beginning to end, the second edition of this hands-on guide demonstrates the practical advantages of test-driven development (TDD) ...

    Test Driven Development_A J2EE Example

    测试驱动开发(Test-Driven Development, TDD)是一种软件开发方法论,它强调在编写功能代码之前先编写测试用例。这种方法有助于确保代码质量,并能提高软件的可维护性和可扩展性。本书《测试驱动开发:一个J2EE实例...

    Test-Driven Development: A Practical Guide

    **测试驱动开发(Test-Driven Development,TDD):实践指南** 测试驱动开发是一种软件开发方法,由Kent Beck在2003年提出并推广,它强调先编写测试,然后编写满足这些测试的代码。TDD的核心原则是“测试先行”,即...

    Professional Test Driven Development with.Csharp

    附录部分提供了几个TDD实践案例,帮助读者更好地理解和应用TDD原理。 通过以上内容,可以看出《专业测试驱动开发与C#》这本书旨在为开发者提供一套全面的TDD指南,不仅覆盖了基本概念和技术,还深入到了实际项目的...

    Practical Test-Driven Development using C# 7.epub

    Test-Driven Development (TDD) is a methodology that helps you to write as little as code as possible to satisfy software requirements, and ensures that what you've written does what it's supposed to ...

    Test-Driven Development with Python 【第二版】

    the updated second edition of this hands-on guide demonstrates the practical advantages of test-driven development (TDD) with Python. You’ll learn how to write and run tests before building each ...

    Test-Driven Java Development(PACKT,2015)

    Test-driven development (TDD) is a development approach that relies on a test-first procedure that emphasises writing a test before writing the necessary code, and then refactoring the code to ...

    test driven development by example

    《测试驱动开发示例》是由Kent Beck撰写的一本关于TDD(Test-Driven Development,测试驱动开发)的经典书籍。本书特别适合Java开发人员阅读,它不仅介绍了TDD的基本概念和实践方法,还通过实际案例,一步步带领读者...

    Modern C++ Programming with Test-Driven Development(Pragmatic,2013)

    Test-driven development (TDD) is a modern software development practice that can dramatically reduce the number of defects in systems, produce more maintainable code, and give you the confidence to ...

Global site tag (gtag.js) - Google Analytics