SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit TestingMike Lively
 
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 2015CiaranMcNulty
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummiesHarry Potter
 
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingGetting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingMark Rickerby
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitMichelangelo van Dam
 
Unit Testing Presentation
Unit Testing PresentationUnit Testing Presentation
Unit Testing Presentationnicobn
 
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 TDDPaweł Michalik
 
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 8Garth Gilmour
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtestWill Shen
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingOrtus Solutions, Corp
 
Implementing a decorator for thread synchronisation.
Implementing a decorator for thread synchronisation.Implementing a decorator for thread synchronisation.
Implementing a decorator for thread synchronisation.Graham Dumpleton
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytestSuraj Deshmukh
 
Keep your repo clean
Keep your repo cleanKeep your repo clean
Keep your repo cleanHector Canto
 

La actualidad más candente (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
 

Destacado

Rashmi Sinha
Rashmi SinhaRashmi Sinha
Rashmi Sinhatieadmin
 
Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)Who Is Muhammad (Pbuh)
Who Is Muhammad (Pbuh)Syukran
 
Lesson17vocab
Lesson17vocabLesson17vocab
Lesson17vocabPEDH
 
Bathing the newborn
Bathing the newbornBathing the newborn
Bathing the newbornsaradar
 
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
 
Tata Cara Syarat Dan Surat Referensi
Tata Cara Syarat Dan Surat ReferensiTata Cara Syarat Dan Surat Referensi
Tata Cara Syarat Dan Surat ReferensiWikimedia Indonesia
 
Mimic Me General Information English
Mimic Me General Information EnglishMimic Me General Information English
Mimic Me General Information Englishcorne3d
 
Wiki Sabanda - Cara Membuat Artikel
Wiki Sabanda - Cara Membuat ArtikelWiki Sabanda - Cara Membuat Artikel
Wiki Sabanda - Cara Membuat ArtikelWikimedia Indonesia
 
David Rodnitzky
David RodnitzkyDavid Rodnitzky
David Rodnitzkytieadmin
 
How to become a design Rockstar
How to become a design RockstarHow to become a design Rockstar
How to become a design RockstarSyukran
 
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 marketingStefan Verhoeve
 
T3dallas typoscript
T3dallas typoscriptT3dallas typoscript
T3dallas typoscriptzdavis
 
Shari Gunn
Shari GunnShari Gunn
Shari Gunntieadmin
 
Return of the Sponsor: Brand Fiction
Return of the Sponsor: Brand FictionReturn of the Sponsor: Brand Fiction
Return of the Sponsor: Brand FictionHelen Klein Ross
 

Destacado (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
 

Similar a Test in action – week 1

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 2022Mark Niebergall
 
Unit tests = maintenance hell ?
Unit tests = maintenance hell ? Unit tests = maintenance hell ?
Unit tests = maintenance hell ? Thibaud Desodt
 
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 - phpdublinMichelangelo van Dam
 
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 8Jay Friendly
 
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] 2023Mark Niebergall
 
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 developmentStephen Fuqua
 
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 applicationsOrtus Solutions, Corp
 
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)Rob Hale
 
Scientific Software Development
Scientific Software DevelopmentScientific Software Development
Scientific Software Developmentjalle6
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
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 2021Scott Keck-Warren
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-appsVenkata Ramana
 
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 SeoulJongwook Woo
 
Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010Unit Testing in SharePoint 2010
Unit Testing in SharePoint 2010Chris Weldon
 
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 Coherencearagozin
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the UntestableMark Baker
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock FrameworkEugene Dvorkin
 
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 jasmineGil Fink
 

Similar a 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
 

Último

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Último (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

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