Practiced AgileDeveloper with TDD andBDDby Sakares SaengkaewSoftware Development and Quality Improvement,Asian Institute of Technology
How many hours testing of yoursoftware? When will you performtesting? What happens?● 8 hours?● 10 % of project work hours.● before deployment 5 days and some bugsstill be unsolved left.● complicate unsolvable bug.● Need more time to debug.● Just show to customer and wish they will notsee unexpected scene.
How should we make itbetter?- Change the way of codingby TDD !
Whats TDD ?- abbreviated from "Test Driven Development".- a programming technique based on a verysimple rule :Only ever write code to fix a failing test.
Whats TDD ?- Test first, then code and design afterward.
Whats TDD ?- But Its not finished yet.- We call it refactoring to better communicatethat the last step is about transforming thecurrent design toward a better design.
How to ?- Using Unit Test. For example, JUnit in Java,BoostTest in C++ or UnitTest in Ruby on Rails.- Perform Red-Green-Refactor principle.
Red-Green-Refactor- Firstly, write a test. Hence, it failed (Red)since there is no functionality code at start.- Secondly, make it pass by simplyimplementing the missing functionality. Then itturn pass (Green).- Last, refactoring. As we improve the design ofthe code without altering its external behavior,all tests should pass and, thus, we shouldremain green.
Brief summary : TDD- TDD is when you use Automated Testing(usually Unit Testing) as a design practice.- TDD ensures high quality code.- Release work with confident.- Make a collective code ownership since unittest suite is a clear document that everydeveloper in teams can read, follow and writeby individual.
But the defect of TDD- The unit tests still test the behavior of themethod.- It may be difficult to trace the behavior of themethod directly to the behavior that the externalstakeholders asked for and/or understand.- Hence, we consider BDD .
Whats BDD ?- abbreviated from "Behavior DrivenDevelopment".- BDD is an extension/revision of TDD.- BDD specifies that tests of any unit ofsoftware should be specified in terms of thedesired behavior of the unit.
Whats BDD ?- Borrowing from agile software developmentthe "desired behavior" in this case consists ofthe requirements set by the business.- BDD utilizes a "Ubiquitous Language", a bodyof knowledge that can be understood by boththe developer and the customer. Moreover, it isused to shape and develop the requirementsand testing needed, at the level of thecustomers understanding.
How to ?- Popular BDD tools include Cucumber, RSpec,SpecFlow and others.- To explain how to perform simply BDD, wewill illustrate from the Cucumber tool by Rubylanguage .
BDD by Cucumber1: Describe behaviour in plain text
BDD by Cucumber2: Write a step definition in Ruby
BDD by Cucumber4: Write code to make the step pass
BDD by Cucumber5: Run again and see the step pass
BDD by Cucumber6: Repeat 2-5 until green like a cuke
Brief summary : BDD- BDD is when you use Automated Testing toflesh out & capture domain logic starting fromthe (high-enough) functional testing down to thedomain unit logic.- BDD ensures high cohesion betweentechnical implementation and the domain.- makes sense to business via the domain unitsand behaviour that domain experts understand.
Summary : Whats differentbetween TDD and BDD ?- BDD focuses on the behavioural aspect of thesystem rather than the implementation aspectof the system that TDD focuses on.- BDD gives a clearer understanding as to whatthe system should do from the perspective ofthe developer and the customer.- TDD only gives the developer anunderstanding of what the system should do.
Summary- One of the principles in agile, "Respondingto change over following a plan". This meansthat do not know in advance what you have tobuild.- TDD and BDD support the change since youcan write exactly needed feature. Also preventoverproduction.
Summary- "Customer collaboration over contractnegotiation". Its clear by using BDD.Customer become to cooperate in softwaredevelopment. Sharpen the product requirementin business aspect.
Reference● Practices of an agile developer: working in the real worldby Venkat Subramaniam, Andy Hunt● Test Driven: Practical TDD and Acceptance TDD for JavaDevelopers by Lasse Koskela● The Cucumber Book: Behaviour-Driven Development forTesters and Developers by Matt Wynne, Matt Wynne● http://www.anitpatel.net/2012/06/14/what-is-the-difference-between-tddatddbdd-in-agile-development/● http://en.wikipedia.org/wiki/Behavior-driven_development● http://programmers.stackexchange.com/questions/21870/can-you-be-agile-without-doing-tdd-test-driven-development● http://cukes.info/