Test Driven Development       An Introduction              by       Lukasz Kujawa
About Me- Lukasz Kujawa- Lead Developer at Gloople- http://systemsarchitect.net/- @lukaszkujawa
What is TDD?"Test-driven development (TDD) is a softwaredevelopment process that relies on the repetition of avery short d...
What is TDD in English?Create test before code
TDD Cycle
RED GREENREFACTOR
The Three Laws of TDD- You might not write production code until youhave written a failing unit test- You might not write ...
TDD Iterations  Test                       Production code  Write minimal Unit Test    Create a Class  Call method of the ...
Unit Testing"In computer programming, unit testing is a method bywhich individual units of source code, sets of one or mor...
Unit Testing in EnglishTesting smallest testable parts of application
Unit Test is not a Test- Very narrow and well defined scope- No complex dependencies- Test only one application layer- Env...
TTD - Too Damn Difficult?
Benefits for Developer- Confidence- Code quality- Time- Refactoring- Reopening issues- Self documenting code
Benefits for Business
Benefits for Business- Shorten development cycles- Delivering more- Stable products
Research 1"Art of Unit Testing" by Roy Osherove  Stage                  Team without tests   Team with tests  Implementati...
Research 2Quality improvement through test drivendevelopment: results and experiences of fourindustrial teams (2008) by Na...
Research 2 Metric             IBM Drivers   Microsoft:   Microsoft:   Microsoft: VS description                      Windo...
How to test?<?phpMyFramework::bootstrap();$obj = new Class_Under_Test();if( $obj->something(Foo) != 47 ) {      throw new ...
Unit Test Frameworks- PHPUnit- SimpleTest
Using Framework- API- No maintenance- Integration with IDE- Code coverage report- Mocks
<?phpclass MyClassTest extends PHPUnit_Framework_TestCase {    public static function setUpBeforeClass() {      MyFramewor...
PHPUnit - Eclipse integration
Unit Testing - small print- Cant test directly private, protected and staticmethods- Tests only functionality- Database- R...
SHOULD I TRY IT?YESREFACTOR
Q&A
Test driven development
Upcoming SlideShare
Loading in...5
×

Test driven development

505

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
505
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Test driven development

  1. 1. Test Driven Development An Introduction by Lukasz Kujawa
  2. 2. About Me- Lukasz Kujawa- Lead Developer at Gloople- http://systemsarchitect.net/- @lukaszkujawa
  3. 3. What is TDD?"Test-driven development (TDD) is a softwaredevelopment process that relies on the repetition of avery short development cycle: first the developer writesan (initially failing) automated test case that defines adesired improvement or new function, then produces theminimum amount of code to pass that test, and finallyrefactors the new code to acceptable standards"- Wikipedia
  4. 4. What is TDD in English?Create test before code
  5. 5. TDD Cycle
  6. 6. RED GREENREFACTOR
  7. 7. The Three Laws of TDD- You might not write production code until youhave written a failing unit test- You might not write more of a unit test than issufficient to fail, and not compiling is failing- You may not write more production code thenis sufficient to pass the currently failing test
  8. 8. TDD Iterations Test Production code Write minimal Unit Test Create a Class Call method of the class Create the Method Assert output of the Add logic to return method expected output
  9. 9. Unit Testing"In computer programming, unit testing is a method bywhich individual units of source code, sets of one or morecomputer program modules together with associatedcontrol data, usage procedures, and operating procedures,are tested to determine if they are fit for use."- Wikipedia
  10. 10. Unit Testing in EnglishTesting smallest testable parts of application
  11. 11. Unit Test is not a Test- Very narrow and well defined scope- No complex dependencies- Test only one application layer- Environment independent- Fast
  12. 12. TTD - Too Damn Difficult?
  13. 13. Benefits for Developer- Confidence- Code quality- Time- Refactoring- Reopening issues- Self documenting code
  14. 14. Benefits for Business
  15. 15. Benefits for Business- Shorten development cycles- Delivering more- Stable products
  16. 16. Research 1"Art of Unit Testing" by Roy Osherove Stage Team without tests Team with tests Implementation 7 days 14 days (coding) Integration 7 days 2 days Testing / Bug Fixing 12 days 8 days Overall release time 26 days 24 days Bugs in production 71 11
  17. 17. Research 2Quality improvement through test drivendevelopment: results and experiences of fourindustrial teams (2008) by NachiappanNagappan, E. Michael Maximilien, ThirumaleshBhat and Laurie Williamshttp://biblio.gdinwiddie.com/biblio/StudiesOfTestDrivenDevelopment
  18. 18. Research 2 Metric IBM Drivers Microsoft: Microsoft: Microsoft: VS description Windows MSN Defect density W X Y Z of comparable team in organization but not using TDD Defect density 0.61W 0.38X 0.24Y 0.09Z of team using TDD Increase in time 15-20% 25-35% 15% 20-25% taken to code the feature because of TDD (%)
  19. 19. How to test?<?phpMyFramework::bootstrap();$obj = new Class_Under_Test();if( $obj->something(Foo) != 47 ) { throw new Exception(Incorrect output for Foo);}if( $obj->someting(Bar) !== false ) { throw new Exception(Incorrect output for Bar);}
  20. 20. Unit Test Frameworks- PHPUnit- SimpleTest
  21. 21. Using Framework- API- No maintenance- Integration with IDE- Code coverage report- Mocks
  22. 22. <?phpclass MyClassTest extends PHPUnit_Framework_TestCase { public static function setUpBeforeClass() { MyFramework::initAutoloader(); } protected function setUp() { $this->myClass = new MyClass(); } public function testSomething() { $this->assertEquals(1, $this->myClass->something()); } public function testSomethingElse() { $this->assertTrue( $this->myClass->somethingElse() ); $this->assertFalse $this->myClass->somethingElse( 47 ) ); }}
  23. 23. PHPUnit - Eclipse integration
  24. 24. Unit Testing - small print- Cant test directly private, protected and staticmethods- Tests only functionality- Database- Requires rigorous discipline
  25. 25. SHOULD I TRY IT?YESREFACTOR
  26. 26. Q&A
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×