SlideShare a Scribd company logo
Unit TestingHow to make your code rockMike Pearce
Introduction tounit testing
ToesToes
Introduction to Unit Testing
He madePHPUnitSebastianBergmann
History
?Whyuse it
Introduction to Unit Testing
Introduction to Unit Testing
Introduction to Unit Testing
Introduction to Unit Testing
$confidence++
Living Tests
Introduction to Unit Testing
Onto theCODE
Introduction to Unit Testing
%> phpunit --skeleton-test
Introduction to Unit Testing
Introduction to Unit Testing
%> phpunitunittests
Introduction to Unit Testing
Introduction to Unit Testing
Introduction to Unit Testing
%> phpunitunittests
Introduction to Unit Testing
Introduction to Unit Testing
Introduction to Unit Testing
%> phpunitunittests
Introduction to Unit Testing
Other testmethods
stubs
mock objects
Introduction to Unit Testing
Not a database table
Introduction to Unit Testing
Extending
xinc
broken build
Testharness
test suite
selenium
AutomatedTestingRobot
Hi!AutomatedTestingRobot
and now...TDD!
sdrawkcaB
Remember this?%> phpunit --skeleton-test
%> phpunit --skeleton-class
Introduction to Unit Testing
and now...BDD!
it’sNOTtesting...
Huh?
So if it's not about testing, what's it about?It's about figuring out what you are trying to do before you run off half-cocked to try to do it. You write a specification that nails down a small aspect of behaviour in a concise, unambiguous, and executable form.Dave Astel
www.phpunit.de/manual/current/en/behaviour-driven-development.html#behaviour-driven-development.bowlinggame-example
questions?
more info...http://en.wikipedia.org/wiki/Portal:Software_Testinghttp://phpunit.dehttp://en.wikipedia.org/wiki/PHPUnithttp://www.ohloh.net/p/phpunit_pocket_guidehttp://www.youtube.com/watch?v=28KGs9c0bSw (Part 1,2...4)This presentation on Slideshare.net:
flickr attributions* hiro008tm-tmmalingering...someonestolemynameEricNixonHryck.BalakovAdam Foster | CodeforZenSebastian BergmannFlySi....Tim

More Related Content

PPTX
Verdades e mentiras sobre teste de software no mundo magico do agile
PPT
Test Driven Development Part 1
PDF
TDD and Simple Design Workshop - Session 1 - November 2018
PDF
TDD and Getting Paid
PDF
TDD and Simple Design Workshop - Session 1 - March 2019
PPTX
클린 테스트
PPT
Testing In Django
PDF
Charlie Talk - Clover
Verdades e mentiras sobre teste de software no mundo magico do agile
Test Driven Development Part 1
TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Getting Paid
TDD and Simple Design Workshop - Session 1 - March 2019
클린 테스트
Testing In Django
Charlie Talk - Clover

Similar to Introduction to Unit Testing (15)

PDF
PHPUnit with Magento
PPT
Unit testing php-unit - phing - selenium_v2
PPTX
Automated Testing but like for PowerShell (April 2012)
PPTX
Getting Started with Test-Driven Development at Longhorn PHP 2023
PDF
Test driven development - Zombie proof your code
PPTX
Getting Started with Test-Driven Development at Longhorn PHP 2023
PPT
Automated Unit Testing
PPTX
ASP.NET 5 & Unit Testing
PPTX
PHPUnit: from zero to hero
PPTX
Unit Testing talk
PPTX
Getting Started with Test-Driven Development at PHPtek 2023
PPTX
Testing of React JS app
PDF
Cursus phpunit
PPTX
ASP.NET & Unit Testing
PHPUnit with Magento
Unit testing php-unit - phing - selenium_v2
Automated Testing but like for PowerShell (April 2012)
Getting Started with Test-Driven Development at Longhorn PHP 2023
Test driven development - Zombie proof your code
Getting Started with Test-Driven Development at Longhorn PHP 2023
Automated Unit Testing
ASP.NET 5 & Unit Testing
PHPUnit: from zero to hero
Unit Testing talk
Getting Started with Test-Driven Development at PHPtek 2023
Testing of React JS app
Cursus phpunit
ASP.NET & Unit Testing
Ad

More from Mike Pearce (7)

PDF
Agile Estimation
PDF
The Shuhari of Agile
PDF
Being Agile
PDF
UX For Developers
PDF
Thimbl: decentralised, open source, micro-blogging
KEY
Api anti patterns
PDF
Writing Effective User Stories
Agile Estimation
The Shuhari of Agile
Being Agile
UX For Developers
Thimbl: decentralised, open source, micro-blogging
Api anti patterns
Writing Effective User Stories
Ad

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Network Security Unit 5.pdf for BCA BBA.
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
Big Data Technologies - Introduction.pptx

Introduction to Unit Testing

Editor's Notes

  • #3: - This presentation WILL NOT teach you how to unit test, it will introduce you to the concept, a brief overview of how to do it, how you can extend it and how it links to TDD
  • #4: - Pura already introduced us to the concept of TDD.- Before we can start pure TDD, we need to understand Unit Testing- UT is the meat of TDD, without a thorough understanding, TDD is all but impossible.
  • #5: - Unit testing is the act of testing the smallest testable part of a code, a "unit"- Unit testing should become second nature- Unit testing can also be automated, more about that at the end.- This pres will introduce you to the way I did unit testing for the STS front end.
  • #6: - This pres. is about PHPUnit.- Pura has already successfully been using SimpleTest and will demonstrate his findings later.- We need to decide which is more suitable. PHPUnit, SimpleTest or both!
  • #7: - PHPUnit is one of the xUnit (collective term for the UNIT tests ie: JUnit, PHPUnit, RUnit. Started with Sunit for smalltalk) family of frameworks that originated with Kent Beck's SUnit.- sUnit was written to test small talk and was later adapted to jUnit for Java and then further to PHPUnit for PHP.
  • #9: Imowreck666Small bugs
  • #10: Opo TerserBig Bugs
  • #11:  conorwithonenYoung code* hiro008
  • #12:  conorwithonenYoung codeOld code* hiro008
  • #13: When developing and adding tests, running the tests and seeing them pass increases confidence in what you're doing, but, don't become complacent.Also...
  • #14: Living Documentation of the system; unit tests can be run independantly to see how a method works
  • #15: tm-tmBeware------------- Unit testing can never test everything- You can't possibly test all variations of input (unless it is absolutely expected)- UT should never be completley relied on- Still need integration testing and manual QA- You should also use version control, if a test that failed previously passed, then you'll need to go and look at why it passed to compare with why it fails (unless it is obvious).- Any failed tests should be identified and the problem fixed immediately otherwise the app will evolve out of sync with the tests and no-one will trust them making them useless.- Unit testing may add significant time (ex: if you have a function that returns boolean TRUE/FALSE, you need to write two tests that test both outcomes.)
  • #17: This is the class we want to test.
  • #21: malingering/
  • #23: This is the class we want to test.public function someFunction($parameterOne, $parameterTwo) { return ((int)$paramterOne == $parameterTwo ? TRUE : FALSE);}
  • #25: mailo [...someonestolemyname]
  • #26: Ricky Romero
  • #29: EricNixon
  • #32: A stub replaces a real component on which the SUT (subject under test) depends on. This, for example, could be a “model” which will never actually looks in the database, it just returns a predefined set of data
  • #33: A mock object is an object which replaces a real object in the execution of code. Similar to stubs, they don’t just return data, they check the data they are given is sane first then return pre-defined data. They can be used to throw exception in your test suite/harness to report errors in execution.It might be that you can’t directly test a method/class (it might be private, or otherwise not easily executable from external to the class). In that case, if the method/class accepted an object, you could pass it a mock object that had all the attributes of the real object, but also did some testing as it went about it’s business.
  • #34: Hryck.
  • #35: You can also test code that mutates data in a db.
  • #36: Simply put, you provide PHPUnit with an XML document describing the database before and after a test, then run the test, then ask PHPUnit to check the two files against the database. You can also add filters to the database tests, for example if your database has a datetime column you’ll never be able to test it, so you can filter that kind of stuff out.
  • #37: What else can you do?
  • #38: BalakovXinc is our continual integration server (or CI Server for short)Xinc watches your every move, like some draconian overlord. If you commit something to the repo with broken tests or a code coverage percentage lower than the overlord likes
  • #39: Adam Foster | Codefor You’ll have “broken the build” Everyone will be alerted and shame will be poured upon you… Naughty.
  • #40: ZenTest harness or automated test framework is a collection of software and test data configured to test a program unit by running it under varying conditions and monitoring its behaviour and outputs. It can test at a higher level, ensuring the program “does what it is supposed to do”
  • #41: A collection of test cases that test specific scenariosLess commonly known as a “validation suite”Test each “part” seperately A “part” can be a method, or a class, or a bunch of methods. Depending on what’s appropriate.
  • #42: Sebastian Bergmann Selenium is a suite of tools to automate web app testing across many platforms. Specialises in front end testing (ie: testing web interfaces)
  • #43: FlySiYou can think of it as your “automated testing robot” Like a QA guy you can get to run your tests many, many times
  • #44: FlySi He won’t mind. He’s used to it. He can test all your form fields, your logins. With a known set of data, he can test data consistency, data accuracy and data validity. Selenium will actually open your target URL in a browser of your choosing, and check it renders correctly ( to a point, it’s not a messiah ). Failing tests if it finds things it doesn’t recognise or is unable to assert as true.
  • #45: - Finally, on to TDD
  • #46: It’s very much like I just described ... But backwards.First, you write your tests. Once you’ve done unit testing for a while, you’ll get a feel for what a test should do. You’ll be surprised, it’s not always about testing each method, but a group of methods (test harness)
  • #48: ....TimRunning this ...
  • #49: Creates this...
  • #50: Behaviour Driven Development (not Business Driven Development, although it could be!)ITS NOT TESTING!
  • #51: Behaviour Driven Development (not Business Driven Development, although it could be!)ITS NOT TESTING!