Cursus phpunit

Click here to load reader

  • date post

    17-May-2015
  • Category

    Technology

  • view

    14.977
  • download

    5

Embed Size (px)

description

Free excerpt of my PHPUnit Training Course

Transcript of Cursus phpunit

  • 1. TRAINING COURSE PHPUNIT Training Course PHPUnit Training Course PHPUnit Nick Belhomme 2010 p. 1

2. TRAINING COURSE PHPUNIT Goal of this course We will introduce you into the art of unit testing. What is Unit testing and how does it work. Together we will build a testing suite for a domain model (computer text based game) and finally implement this model into Zend Framework 1.11 and up. Making you comfortable with the PHPUnit testing framework. Training Course PHPUnit Nick Belhomme 2010 p. 2 3. TRAINING COURSE PHPUNIT What where how? Training Course PHPUnit Nick Belhomme 2010 p. 3 4. TRAINING COURSE PHPUNIT What is Unit Testing? Unit Testing is the testing of units. The tests are done to ensure that each unit is working like it is intended to work. The tests should be automatic and performed on regular intervals performing validation and verification on the correct working of the units tested. Ideally each test should be independent of another. A unit to be tested is a small piece of software code. Today in Object oriented programming languages these small pieces of software code are generally individual methods from a specific class. Unit testing gives us a way to test our implementations, design and behavior on the classes we write. Today we can claim that Unit testing is a fundamental part of quality modern software development. Benefits of Unit Testing Unit testing has three main benefits: It makes you think about your application and about the implementation route you have chosen / are about to chose instead of running off half cocked implementing bad design decisions. It gives an immediate view on the proper functioning of the system and facilitates locating a defect in the system. It facilitates the refactoring of existing code. Which is equally important to guarantee the longevity of an application. "Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. It is a disciplined way to clean up code that minimizes the chances of introducing bugs. [Preface Refactoring Martin Fowler]" When something breaks the application because of external factors (ie. DB credential changes) or because changes made to the code, Unit Tests will quickly show you were the error or bug has been introduced. Allowing you to quickly locate and fix the bug. In the end speeding up development time. Because of the tests in place you as a developer will feel more confident in your code and in your future changes. Reflecting that confidence to customers, management and other developers. Training Course PHPUnit Nick Belhomme 2010 p. 4 5. TRAINING COURSE PHPUNIT Testing pieces of software Mostly for (PHP) developers testing their code was programming something and displaying it in the browser. If it worked we moved on to the next piece of software to implement. In a modern development cycle unit testing is a core component. Instead of testing stuff in the browser we also test by automating different scenarios. In general if you think you need a var_dump() for testing your code, you are better of making that test eternally embedded in your test-suite. Martin-Fowler Every programmer makes mistakes. What differentiates the good from the bad is that the good programmer uses tests to detect his mistakes ASAP. Reducing debugging costs to a minimum and making the product more stable. Okay up to our first test. We are going to test the CAST operator