2. Our story by unit testing classes Started from inside to the outside
3.
4. PHPUnit class TestClass extends PHPUnit_Framework_TestCase { public function setUp () {} public function testMethod () {} public function tearDown () {} }
5. Problems No integration guarantees Not effective for refactoring legacy code Does not ensure external quality
7. Unit testing DAOs with DI and mocks $connection = createMockExpecting( " INSERT INTO table SET field = 'value' " ); $dao = new Dao( $connection ); $dao -> insert ( 'value' ); Tells nothing about the database interaction
8. Testing DAOs - injected connection $connection = createLocalTestConnection(); $dao = new Dao( $connection ); $dao -> insert ( 'value' ); assertInsertedValueMatches( 'value' ); Hard to replace in end to end tests
23. Excercise VideoPublisherDao :: create () -> publish ( $video -> id ); Http service DAO HttpClient :: create () -> call ( 'Video::publish' , $video -> id );
24.
25.
26. The power of layer crossing tests Refactoring (legacy) code Increasing code coverage
27.
28. Concurrent end-to-end black box tests Uses only the front door (public api) Isolation with unique identifiers & Δ assertions Tests real concurrency Harder to track bugs & intermittent tests http://engineering.imvu.com/2011/01/19/buildbot-and-intermittent-tests/