Test Driven Development

15

Transcript of Test Driven Development

Page 1: Test Driven Development
Page 2: Test Driven Development

Content What is TTD?Unit Test & RefactoringGot Bugs?Tenets of TTD.Benifits of TDD.Advantages & Disadvantages of TDD.

Page 3: Test Driven Development

What is TDD? It is just about writing the test before the

program.It’s a testing technique as well as a design

Technique.In the end, there is no code without a test.The developer can tell at any time.Unit Tests and Refactoring are the tools of

TDD.

Page 4: Test Driven Development

Unit Tests Easy to read & understand.Execute very quickly.Independent of execution order.Test specific aspects of a functionality.Tests a very small section of code isolation.Rapid feedback.

Page 5: Test Driven Development

Refactoring Take existing code & change it more efficient.Change the internal structure of code without

changing its external behavior.Ex :-•ab + ac = a(b+c)

Same result, but the expression is simplified.

Page 6: Test Driven Development

Start Write a test for new capability

Compile

Fix compile errors

Run the testRun the testAnd see it failAnd see it fail

Write the code

Run the testRun the testAnd see it passAnd see it pass

RefactorRefactor as needed as needed

Red/Green/Refactor

Page 7: Test Driven Development

Got bugs? Go after defect. Writing a test to expose it..Write code needed to fix it.Refactor.Repeat.Measure the result.

Page 8: Test Driven Development

Tenets of TDD Split work into small requirements. Always start by writing a test.Eliminate duplication.Write the simple code to pass the test.

Page 9: Test Driven Development

What can test by TDD? Valid inputs. Invalid inputs.Errors, exceptions and events.Boundary conditions.

Page 10: Test Driven Development

Benefits for Developers Much less debug time. Code proven to meet requirement.Test become Safety Net.Process consulting.Project mentoring.Eliminate bugs.

Page 11: Test Driven Development

Benefits for Business Shorter development cycles. Near zero defect.Test become an asset.Test are documentation.Competitive advantage.

Page 12: Test Driven Development

Gets running code very quickly.Development in small steps. This will make

debugging easier since we will have small code chunks to debug.

Produce fully testable code.Design to the specification, don’t over

engineer.

Advantages

Page 13: Test Driven Development

“Write test, write code to pass test, repeat” loop is overly strict.

Setup requires some what complex wiring.Causes people to take paths they wouldn’t

otherwise.

Disadvantages

Page 14: Test Driven Development

References “Test-Driven Development By Example”; Kent

Beck;2003.“Refactoring, Improving The Design Of Existing

Code”; Martin Fowler;1999. “Patterns Of Enterprise Application

Architecture”; Martin Fowler;2003.

Page 15: Test Driven Development