SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Test in Action – Week 1
      Introduction
      Hubert Chan
What is Test?
• Testing
  – Definition
     • Verification between actual and expected result
  – Example
     • fibonacci(6) == 8
     • Fill <script> string in input box, there is no XSS hole
Definition of Test – Unit Test
• Unit Test
  – Write code to test your code
  – White box testing
  – Unit Under Test
     • Class
     • Function
Definition of Test – Unit Test
• Single Failure Point
  – Limited Dependency
  – Limited to
     • Module
     • Class
Unit Testing Example
• Fibonacci Number
  function fib($n) {
      if ($n < 3 ) {
          return 1;
      } else {
          return fib($n-1) + fib($n-2);
      }
  }
Unit Testing Example
• Test Code
  require_once(__DIR__ . '/fib.php');

  class FibTest extends PHPUnit_Framework_TestCase
  {
      public function testfib() {
          $res = fib(6);
          $this->assertEquals(8, $res);
      }
  }
Unit Testing Example
• Handler Test Code
  class LogHandlerTest extends PHPUnit_Framework_TestCase
  {
      public function test_generate_ajax_expect_json() {
          $handler = new LogHandler();
          $res_json = $handler->generate_ajax();
          $expect_json = "...";
          $this->assertEquals($expect_json, $res_json);
      }
  }
Definition of Test – Integration Test
• Integration Test
  – Testing more dependent modules as a group
  – Black Box Testing
  – Usage Model Testing
     • Feature Based Testing
     • User Targeted Testing
Definition of Test – Integration Test
• Multiple Failure Point
  – Dependency
  – System Wise
Integration Test Example
• Selenium Example
  <?php
  require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

  class WebTest extends PHPUnit_Extensions_SeleniumTestCase {
      protected function setUp() {
          $this->setBrowser('*firefox');
          $this->setBrowserUrl('http://www.example.com/');
      }

      public function testTitle() {
          $this->open('http://www.example.com/');
          $this->assertTitle('Example WWW Page');
      }
  }
Difference
                       Unit Testing   Integration Test
Speed                  Fast           Relatively Slow
Failure Point          Less           More
Test Coverage          Better         Neutral (*)
Failure Path Testing   Easier         Harder
Benefit of Test
• Facilitates Change
  – Ensure modules still work correctly after change
  – Foundation of change
     • Feature change
     • Refactoring
What’s good Unit Test
• Good Unit Test
  – Automated and repeatable
  – Reliable and consistent result
  – Focus on units
  – Anyone/CI should be able to run it
  – It should run at the push of a button
  – It should run quickly
Benefit of Unit Test
• Software Quality Enhancement
  – Verification
     • Catch bugs in code level
     • Faster than integration test
     • Quality Enforcing
  – Faster bug identification
     • Identify the bugs location
Benefit of Unit Test
• Documentation
  – Living documentation of the module
  – Gain a basic understanding of the unit API
Benefit of Unit Test
• Code Quality Enhancement
  – Foundation of Refactoring
  – Test drives better OO design
     • Good OO design is essential for unit test
  – Testability
     • Singleton => Anti-Pattern for testing
Hard to do Unit Test?
• Why?
  – Too complex
     • Violate Single Responsibility Principle
  – Breaking encapsulation
  – Not program by interface
  – Messy hierarchy and responsibility
What’s TDD?
• Principle
  – Red
  – Green
  – Refactor
TDD – Red
• Red
  – Before actual implementation
  – Write a test that fails
TDD – Red (Example)
• Red
  – Before writing LogHandler implementation
  – Write the test code first
  class LogHandlerTest extends PHPUnit_Framework_TestCase
  {
      public function test_generate_ajax_expect_json() {
          $handler = new LogHandler();
          $res_json = $handler->generate_ajax();
          $expect_json = "...";
          $this->assertEquals($expect_json, $res_json);
      }
  }
TDD – Green
• Green
  – Make the code work
  – Using mock/stub for dependency
TDD – Green (Example)
• Green (Example)
  class LogHander {
      private dbmodel;
      public function generate_ajax() {
          $data = dbmodel->query();
          return $this->data_to_json($data);
      }
      protected function data_to_json($data) {
        // processing
        ...
        return json_encode($res);
      }
  }
TDD – Green (Example)
• In Green Example
  – Faking in TDD
     • We need a “fake” dbmodel
     • Can dbmodel->query() return dummy data?
  – Think
     • How do we fake it?
     • Is it a good responsibility for module?
TDD – Refactor
• Refactor
  – Do Refactoring
  – Implement Real dbmodel
  – It breaks the test
     • Repeat another TDD cycle
Benefit of TDD
• Benefit
  – Make you think about your design
     • Design by Contract
     • Modularize/Flexible/Extensible
  – Enforce you have tests
Continuous Integration
• Continuous Integration
  – Automation
     • Build
     • Testing
  – More
     • Static Code Analysis
     • Test Coverage
     • Coding Style Checking
Continuous Integration
• Benefit of Continuous Integration
  – Fully automate
  – Catch and enforce to fix bugs
  – Report
Q&A
• How do you think about testing?
• Think about
  – TDD / Testing is not elixir
  – BDD and ATDD
  – Real OO design
  – Legacy Code

Weitere ähnliche Inhalte

Was ist angesagt?

Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
Harry Potter
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
nicobn
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
Will Shen
 

Was ist angesagt? (20)

Java best practices
Java best practicesJava best practices
Java best practices
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingGetting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe Testing
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentation
 
Unit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDDUnit testing with PHPUnit - there's life outside of TDD
Unit testing with PHPUnit - there's life outside of TDD
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Java 8 ​and ​Best Practices
Java 8 ​and ​Best PracticesJava 8 ​and ​Best Practices
Java 8 ​and ​Best Practices
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
TDD Training
TDD TrainingTDD Training
TDD Training
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration Testing
 
Implementing a decorator for thread synchronisation.
Implementing a decorator for thread synchronisation.Implementing a decorator for thread synchronisation.
Implementing a decorator for thread synchronisation.
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
Keep your repo clean
Keep your repo cleanKeep your repo clean
Keep your repo clean
 

Andere mochten auch

Rashmi Sinha
Rashmi SinhaRashmi Sinha
Rashmi Sinha
tieadmin
 
Lesson17vocab
Lesson17vocabLesson17vocab
Lesson17vocab
PEDH
 
What can Michelangelo teach us about innovation?
What can Michelangelo teach us about innovation?What can Michelangelo teach us about innovation?
What can Michelangelo teach us about innovation?
Aman Narain
 
Mimic Me General Information English
Mimic Me General Information EnglishMimic Me General Information English
Mimic Me General Information English
corne3d
 
How to become a design Rockstar
How to become a design RockstarHow to become a design Rockstar
How to become a design Rockstar
Syukran
 
Presentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketing
Presentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketingPresentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketing
Presentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketing
Stefan Verhoeve
 

Andere mochten auch (20)

Rashmi Sinha
Rashmi SinhaRashmi Sinha
Rashmi Sinha
 
Aspen Lion
Aspen LionAspen Lion
Aspen Lion
 
Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)
 
Lesson17vocab
Lesson17vocabLesson17vocab
Lesson17vocab
 
Bathing the newborn
Bathing the newbornBathing the newborn
Bathing the newborn
 
What can Michelangelo teach us about innovation?
What can Michelangelo teach us about innovation?What can Michelangelo teach us about innovation?
What can Michelangelo teach us about innovation?
 
Jorge Caballero Peru Lac English Final
Jorge Caballero Peru Lac English FinalJorge Caballero Peru Lac English Final
Jorge Caballero Peru Lac English Final
 
Wsp Lac Vienna 2009 4 Jun
Wsp Lac Vienna 2009 4 JunWsp Lac Vienna 2009 4 Jun
Wsp Lac Vienna 2009 4 Jun
 
Organisasi Dan Proyek
Organisasi Dan ProyekOrganisasi Dan Proyek
Organisasi Dan Proyek
 
Tata Cara Syarat Dan Surat Referensi
Tata Cara Syarat Dan Surat ReferensiTata Cara Syarat Dan Surat Referensi
Tata Cara Syarat Dan Surat Referensi
 
Mimic Me General Information English
Mimic Me General Information EnglishMimic Me General Information English
Mimic Me General Information English
 
Wiki Sabanda - Cara Membuat Artikel
Wiki Sabanda - Cara Membuat ArtikelWiki Sabanda - Cara Membuat Artikel
Wiki Sabanda - Cara Membuat Artikel
 
David Rodnitzky
David RodnitzkyDavid Rodnitzky
David Rodnitzky
 
How to become a design Rockstar
How to become a design RockstarHow to become a design Rockstar
How to become a design Rockstar
 
Presentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketing
Presentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketingPresentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketing
Presentatie Hogeschool Rotterdam - Van bedrijfseconomie naar marketing
 
Proposal Papat Limpad
Proposal Papat LimpadProposal Papat Limpad
Proposal Papat Limpad
 
T3dallas typoscript
T3dallas typoscriptT3dallas typoscript
T3dallas typoscript
 
Formulir anggota WMID
Formulir anggota WMIDFormulir anggota WMID
Formulir anggota WMID
 
Shari Gunn
Shari GunnShari Gunn
Shari Gunn
 
Return of the Sponsor: Brand Fiction
Return of the Sponsor: Brand FictionReturn of the Sponsor: Brand Fiction
Return of the Sponsor: Brand Fiction
 

Ähnlich wie Test in action – week 1

Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
Ortus Solutions, Corp
 
Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010
Chris Weldon
 

Ähnlich wie Test in action – week 1 (20)

Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
 
Unit tests = maintenance hell ?
Unit tests = maintenance hell ? Unit tests = maintenance hell ?
Unit tests = maintenance hell ?
 
Workshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublinWorkshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublin
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit Testing
 
Unit testing
Unit testingUnit testing
Unit testing
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 
Scientific Software Development
Scientific Software DevelopmentScientific Software Development
Scientific Software Development
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps
 
2014 International Software Testing Conference in Seoul
2014 International Software Testing Conference in Seoul2014 International Software Testing Conference in Seoul
2014 International Software Testing Conference in Seoul
 
Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010
 
Performance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle CoherencePerformance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle Coherence
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the Untestable
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Test in action – week 1

  • 1. Test in Action – Week 1 Introduction Hubert Chan
  • 2. What is Test? • Testing – Definition • Verification between actual and expected result – Example • fibonacci(6) == 8 • Fill <script> string in input box, there is no XSS hole
  • 3. Definition of Test – Unit Test • Unit Test – Write code to test your code – White box testing – Unit Under Test • Class • Function
  • 4. Definition of Test – Unit Test • Single Failure Point – Limited Dependency – Limited to • Module • Class
  • 5. Unit Testing Example • Fibonacci Number function fib($n) { if ($n < 3 ) { return 1; } else { return fib($n-1) + fib($n-2); } }
  • 6. Unit Testing Example • Test Code require_once(__DIR__ . '/fib.php'); class FibTest extends PHPUnit_Framework_TestCase { public function testfib() { $res = fib(6); $this->assertEquals(8, $res); } }
  • 7. Unit Testing Example • Handler Test Code class LogHandlerTest extends PHPUnit_Framework_TestCase { public function test_generate_ajax_expect_json() { $handler = new LogHandler(); $res_json = $handler->generate_ajax(); $expect_json = "..."; $this->assertEquals($expect_json, $res_json); } }
  • 8. Definition of Test – Integration Test • Integration Test – Testing more dependent modules as a group – Black Box Testing – Usage Model Testing • Feature Based Testing • User Targeted Testing
  • 9. Definition of Test – Integration Test • Multiple Failure Point – Dependency – System Wise
  • 10. Integration Test Example • Selenium Example <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class WebTest extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser('*firefox'); $this->setBrowserUrl('http://www.example.com/'); } public function testTitle() { $this->open('http://www.example.com/'); $this->assertTitle('Example WWW Page'); } }
  • 11. Difference Unit Testing Integration Test Speed Fast Relatively Slow Failure Point Less More Test Coverage Better Neutral (*) Failure Path Testing Easier Harder
  • 12. Benefit of Test • Facilitates Change – Ensure modules still work correctly after change – Foundation of change • Feature change • Refactoring
  • 13. What’s good Unit Test • Good Unit Test – Automated and repeatable – Reliable and consistent result – Focus on units – Anyone/CI should be able to run it – It should run at the push of a button – It should run quickly
  • 14. Benefit of Unit Test • Software Quality Enhancement – Verification • Catch bugs in code level • Faster than integration test • Quality Enforcing – Faster bug identification • Identify the bugs location
  • 15. Benefit of Unit Test • Documentation – Living documentation of the module – Gain a basic understanding of the unit API
  • 16. Benefit of Unit Test • Code Quality Enhancement – Foundation of Refactoring – Test drives better OO design • Good OO design is essential for unit test – Testability • Singleton => Anti-Pattern for testing
  • 17. Hard to do Unit Test? • Why? – Too complex • Violate Single Responsibility Principle – Breaking encapsulation – Not program by interface – Messy hierarchy and responsibility
  • 18. What’s TDD? • Principle – Red – Green – Refactor
  • 19. TDD – Red • Red – Before actual implementation – Write a test that fails
  • 20. TDD – Red (Example) • Red – Before writing LogHandler implementation – Write the test code first class LogHandlerTest extends PHPUnit_Framework_TestCase { public function test_generate_ajax_expect_json() { $handler = new LogHandler(); $res_json = $handler->generate_ajax(); $expect_json = "..."; $this->assertEquals($expect_json, $res_json); } }
  • 21. TDD – Green • Green – Make the code work – Using mock/stub for dependency
  • 22. TDD – Green (Example) • Green (Example) class LogHander { private dbmodel; public function generate_ajax() { $data = dbmodel->query(); return $this->data_to_json($data); } protected function data_to_json($data) { // processing ... return json_encode($res); } }
  • 23. TDD – Green (Example) • In Green Example – Faking in TDD • We need a “fake” dbmodel • Can dbmodel->query() return dummy data? – Think • How do we fake it? • Is it a good responsibility for module?
  • 24. TDD – Refactor • Refactor – Do Refactoring – Implement Real dbmodel – It breaks the test • Repeat another TDD cycle
  • 25. Benefit of TDD • Benefit – Make you think about your design • Design by Contract • Modularize/Flexible/Extensible – Enforce you have tests
  • 26. Continuous Integration • Continuous Integration – Automation • Build • Testing – More • Static Code Analysis • Test Coverage • Coding Style Checking
  • 27. Continuous Integration • Benefit of Continuous Integration – Fully automate – Catch and enforce to fix bugs – Report
  • 28. Q&A • How do you think about testing? • Think about – TDD / Testing is not elixir – BDD and ATDD – Real OO design – Legacy Code