(Narrow) driver development unit testing --TDD

Introduction 1. TDD's

       TDD is a core agile development practices and technologies, but also a design methodology. TDD principle is developed before the function code, unit test cases before writing the code, test code to determine what products need to write code. TDD is XP (Extreme Programming) of the core practices.

       TDD broad and narrow sense, narrow sense is often say TDD, which is UTDD (Unit Test Driven Development). TDD is generalized ATDD (Acceptance Test Driven Development), comprising a BDD (Behavior Driven Development) and Consumer-Driven Contracts Development like.

2.TDD encoding the conventional coding

   TDD Encoding:

  • First task decomposition, separation of concerns.
  • Examples are listed, with examples of demand, the demand to clarify the details.
  • Write test, only concerned with input and output requirements, procedures, and do not care about the middle of the process.
  • Write realize, nothing else needs to use the simplest way to meet the current needs of this small can be.
  • Reconstruction, eliminate bad code with the code of practices.
  • Finished, manual test, basically no problem, there are problems with the cases make up a repair.
  • Code is clean and complete use case, confidently commit.

   Traditional encoding:

  • Needs analysis, comparative analysis is difficult to know the details, but a matter of time, had to press a rough understanding of coding.
  • Found in the coding process needs details are not clear and need to be confirmed with the needs of business people.
  • You may need to confirm multiple needs in order to achieve business logic.
  • After writing a bunch of code that may occur when you run a lot of bug and test, so most of the time required to debug and modify.
  • Turn test, QA measured bug, debug, patch

3. Use the benefits of TDD

Appropriate to reduce the workload of developers
through a clear process, let us first focus on one point, thinking the burden on smaller, convenient encoding tests.

Unit testing code quality assurance
TDD benefit is completely covered unit testing, provides a more convenient test for the preparation of product code, allowing developers more convenient to seek a change in the face of changes in demand, in addition, can facilitate the realization improve the design of the code. So that developers submit code quality is relatively high.

Easy to understand business needs
to write test can help us to become familiar with our business needs and the needs of the details found in advance, but when not coding work half after the discovery not explicitly demand.

Quick feedback
when there are a lot of people say TDD, my code amount is increased, the development efficiency is reduced. However, if there is no unit testing, manual testing is required, this will spend a lot of time to prepare data, launch applications, jump interface, the results you want to get feedback will be slow. In other words, rapid feedback is one of the benefits of unit testing.

4.TDD the three rules

  • Unless it is to make a failing unit test pass, otherwise not allowed to write any production code
  • In a unit test, only allows you to write content just to be able to lead to failure (compilation error can be considered failed)
  • Only allows you to write just to make a failing unit test by product code

 

Published 22 original articles · won praise 5 · Views 2193

Guess you like

Origin blog.csdn.net/calm_encode/article/details/103921344