当前位置:网站首页>Yyds dry inventory what is test driven development

Yyds dry inventory what is test driven development

2022-07-06 03:15:00 A drop in the universe

Definition

Test-driven development , English name Test-driven development, It's about a programming style .

There are mainly three processes closely intertwined :

  • code
  • test ( In the form of writing unit tests )
  • Design ( In the form of refactoring )

It can be succinctly described by the following set of rules :

  • Write a unit test , To describe one aspect of the program
  • Run the test , If the program lacks functions, it will fail
  • To write “ Adequate ” Code for , As simple as possible , To make the test pass
  • “ Refactoring code ”, Until it meets the simplicity criteria
  • repeat , as time goes on “ The accumulation of ” unit testing

Expected revenue

If you do this, you may reap benefits :

  • Team code bug A significant reduction in the rate , But the code is a modest increase in the initial development work
  • The same team reported that these indirect costs were offset by a reduction in work at the final stage of the project
  • Although empirical studies so far have failed to confirm this , But senior practitioners report ,TDD It can improve the design quality in the code , And more generally improve “ Inside ” Or technical quality , For example, improve the indicators of cohesion and coupling

Common pitfalls

Typical personal mistakes include :

  • Forget to run tests often
  • Write too many tests at once
  • Write tests that are too large or too coarse
  • Write too trivial tests , For example, omit assertions
  • Write tests for trivial code , For example, accessors

Typical team misconceptions include :

  • Partial use of —— Only a few developers on the team use TDD
  • The test suite is poorly maintained -- The most common reason is that the test suite runs too long
  • Obsolete test suite ( That is, it rarely or never runs )-- Sometimes due to poor maintenance , Sometimes it is caused by the flow of team personnel

origin

Although the idea of testing and refinement before programming is not the original idea of the agile community , but TDD Constitutes a breakthrough , Because it combines this idea with “ Developer testing ” The idea of combining , It provides new respect for developer testing .

  • 1976 year :Glenford Myers Published “ Software reliability ”, Which point out that “ Developers should not test their own code ” Of “ axiom ”( The dark age of developer testing )
  • 1990: With “ Black box ” Technology based testing discipline , Especially with “ Capture and playback ” Form of test tool
  • 1991 year : stay Taligent Independently created a testing framework , And SUnit There are amazing similarities ( source :SUnit).
  • 1994 year :Kent Beck by Smalltalk Write the SUnit The test framework ( source )
  • 1998: The article about extreme programming mentioned “ We usually write tests first ”( source )
  • 1998 Year to 2002 year :“Test First” Elaborated as “Test Driven”, Especially in C2.com Wiki On
  • 2000: Simulation object is one of the new technologies developed in that period ( source )
  • 2003 year :Kent Beck Published “ Test-driven development : Example ”

To 2006 year ,TDD It is already a relatively mature discipline , It has begun to encourage further innovation derived from it , Such as ATDD or BDD).

The logo used

  • “ Code coverage ” Is to prove the use of TDD The common method of ; Although high coverage does not guarantee correct use TDD, But lower than 80% Coverage of may indicate that the team is interested in TDD Insufficient mastery of
  • The version control log should show that the test code is checked in every time the product code is checked in , The quantity is roughly the same

Technical level

beginner

  • Be able to write a unit test before writing the corresponding code
  • Be able to rewrite code enough to pass failed tests

intermediate

  • practice “ Test driven bug fixes ”: When defects are found , Write a test that exposes defects before correcting
  • It can decompose the characteristics of a composite program into several unit test sequences to write
  • Know and be able to say some strategies to guide the writing of tests ( for example ," When testing a recursive algorithm , First write a test for recursive termination ").
  • Be able to find reusable elements from existing unit tests , Test tools that generate specific situations

senior

  • Be able to develop planned unit tests for macro features " The roadmap "( And modify it if necessary )
  • can " Test drive " Various design paradigms : object-oriented 、 Functionalization 、 Event driven
  • can " Test drive " Various technical fields : Calculation 、 The user interface 、 Persistent data access .......

Extended reading

 ​Test Driven Development: By Example​​, by Kent Beck

Link to the original text :https://www.agilealliance.org/glossary/tdd/#q=~(infinite~false~filters~(postType~(~'page~'post~'aa_book~'aa_event_session~'aa_experience_report~'aa_glossary~'aa_research_paper~'aa_video)~tags~(~'tdd))~searchTerm~'~sort~false~sortDirection~'asc~page~1)

原网站

版权声明
本文为[A drop in the universe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202132323129930.html