• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Test-driven development for TYPO3 (T3DD11)
 

Test-driven development for TYPO3 (T3DD11)

on

  • 1,369 views

 

Statistics

Views

Total Views
1,369
Views on SlideShare
1,356
Embed Views
13

Actions

Likes
4
Downloads
0
Comments
0

2 Embeds 13

http://paper.li 7
url_unknown 6

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Test-driven development for TYPO3 (T3DD11) Test-driven development for TYPO3 (T3DD11) Presentation Transcript

  • Test-Driven Developmentfor TYPO3Oliver Klee, 2011-07-08typo3-coding@oliverklee.de
  • Unittests?
  • Manual testing is cumbersome
  • Automatedtesting isfast
  • Unit tests for the Realty Manager extension
  • more than1600 tests
  • in less than 60 seconds
  • Verify that your codedoes what you expect
  • Make sure that yourchanges won‘t break anything
  • Keep other codersfrom breaking your code
  • Don‘t break anythingeven in complex projects
  • Create asafety net for refactoring
  • Green feels good!
  • Green feels good!
  • Know your tools
  • The phpunit extension has it all
  • The phpunit extension has it allphpunit (TYPO3 extension)
  • The phpunit extension has it allphpunit (TYPO3 extension) PHPUnit (PEAR package)
  • The phpunit extension has it allphpunit (TYPO3 extension) PHPUnit (PEAR package) Testrunner (back-end- module)
  • The phpunit extension has it allphpunit (TYPO3 extension) PHPUnit (PEAR package) Testrunner Testrunner (back-end- module) (CLI module)
  • The phpunit extension has it allphpunit (TYPO3 extension) PHPUnit (PEAR package) Testing framework for FE & DB Testrunner Testrunner (back-end- module) (CLI module)
  • Let‘s getsome terms straight
  • Two testsmeet in a bar ...
  • Two testsTest meet in a bar ...
  • Two tests Test meet in aAssertion bar ...
  • Two tests Test meet in aAssertion bar ... Test Test
  • Two tests Test meet in aAssertion bar ... Test TestTest case
  • Two tests Test meet in aAssertion bar ... Test TestTest caseTest case
  • Two tests Test meet in aAssertion bar ... Test TestTest caseTest caseTest suite
  • The life cycle unit test of a
  • The life cycle unit test of a
  • The life cycle unit test of a new FooTest();
  • The life cycle unit test of a new FooTest();
  • The life cycle unit test of a new FooTest(); setUp();
  • The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood();
  • The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood();
  • The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood(); tearDown();
  • The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood(); tearDown();
  • The life cycle unit test of a new FooTest(); setUp(); /** @test */ lifeIsGood(); tearDown();
  • Use meaningful unit test names
  • Use meaningful unit test namesName thebehavior. classCanBeInstantiated
  • Use meaningful unit test names Name the behavior. classCanBeInstantiatedMention the method. setTitleSetsTitle
  • Use meaningful unit test names Name the behavior. classCanBeInstantiatedMention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsExceptionpreconditions. hasTitleForEmptyTitleReturnsFalse
  • Use meaningful unit test names Name the behavior. classCanBeInstantiatedMention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsExceptionpreconditions. hasTitleForEmptyTitleReturnsFalse Dont‘t use "works" or "correctly".
  • Use meaningful unit test names Name the behavior. classCanBeInstantiatedMention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsExceptionpreconditions. hasTitleForEmptyTitleReturnsFalse Dont‘t use "works" or measureFrubbleWorksCorrectly "correctly".
  • Use meaningful unit test names Name the behavior. classCanBeInstantiatedMention the method. setTitleSetsTitle Name the setSizeWithZeroThrowsExceptionpreconditions. hasTitleForEmptyTitleReturnsFalse Dont‘t use "works" or measureFrubbleWorksCorrectly "correctly".
  • Code test-first
  • Code test-first
  • Code test-firstwritetest
  • Code test-firstwritetest
  • Code test-firstwrite writetest code
  • Code test-firstwrite writetest code
  • Code test-firstwrite writetest code
  • Code test-firstwrite writetest code refactor
  • Code test-firstwrite writetest code refactor
  • There are small and huge tests
  • Unit tests are small and fast
  • Integration tests test the complete thing
  • Automated click tests test the interface
  • Automated click tests test the interface Selenium
  • Blackbox tests test the public interface
  • Whitebox tests test the inner workings
  • The testing framework is created quickly /** * @var Tx_Phpunit_Framework */ protected $testingFramework = NULL; public function setUp() { $this->testingFramework = new Tx_Phpunit_Framework(tx_news2); } public function tearDown() { $this->testingFramework->cleanUp(); unset($this->testingFramework); }
  • The testing framework is created quickly /** * @var Tx_Phpunit_Framework */ protected $testingFramework = NULL; public function setUp() { $this->testingFramework = new Tx_Phpunit_Framework(tx_news2); } discard the FE, public function tearDown() { delete DB records, $this->testingFramework->cleanUp(); unset($this->testingFramework); delete files }
  • The testing framework is created quickly /** * @var Tx_Phpunit_Framework */ protected $testingFramework = NULL; public function setUp() { $this->testingFramework = new Tx_Phpunit_Framework(tx_news2); } discard the FE, public function tearDown() { delete DB records, $this->testingFramework->cleanUp(); unset($this->testingFramework); delete files }CREATE TABLE tx_news2_domain_model_news ( … is_dummy_record tinyint(1) unsigned DEFAULT 0 NOT NULL, …
  • The testing framework can fake almost everything
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array());
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData);
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid);
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);$tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName);
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);$tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName); $tf->removeRelation($tableName, $uidLocal, $uidForeign);
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);$tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName); $tf->removeRelation($tableName, $uidLocal, $uidForeign); $numberOfRecords = $tf->countRecords($tableName, $whereClause = );
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);$tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName); $tf->removeRelation($tableName, $uidLocal, $uidForeign); $numberOfRecords = $tf->countRecords($tableName, $whereClause = ); $success = $tf->existsRecord($tableName, $whereClause = );
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);$tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName); $tf->removeRelation($tableName, $uidLocal, $uidForeign); $numberOfRecords = $tf->countRecords($tableName, $whereClause = ); $success = $tf->existsRecord($tableName, $whereClause = ); $success = $tf->existsExactlyOneRecord($tableName, $whereClause = );
  • The testing framework can fake almost everything $recordUid = $tf->createRecord($tableName, array $recordData = array()); $tf->changeRecord($tableName, $uid, array $recordData); $tf->deleteRecord($tableName, $uid); $tf->createRelation($tableName, $uidLocal, $uidForeign, $sorting = 0);$tf->createRelationAndUpdateCounter($tableName, $uidLocal, $uidForeign, $columnName); $tf->removeRelation($tableName, $uidLocal, $uidForeign); $numberOfRecords = $tf->countRecords($tableName, $whereClause = ); $success = $tf->existsRecord($tableName, $whereClause = ); $success = $tf->existsExactlyOneRecord($tableName, $whereClause = ); $success = $tf->existsRecordWithUid($tableName, $uid);
  • The testing framework can fake almost everything
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array());
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array());
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array());
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array());
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0);
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd();
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array());
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = , array $recordData = array());
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = , array $recordData = array()); $tf->loginFrontEndUser($userId);
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = , array $recordData = array()); $tf->logoutFrontEndUser(); $tf->loginFrontEndUser($userId);
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = , array $recordData = array()); $tf->logoutFrontEndUser(); $tf->loginFrontEndUser($userId);$userUid = $tf->createAndLoginFrontEndUser($groups = , array $recordData = array());
  • The testing framework can fake almost everything $pageUid = $tf->createFrontEndPage($parentId = 0, array $recordData = array()); $pageUid = $tf->createSystemFolder($parentId = 0, array $recordData = array()); $elementUid = $tf->createContentElement($pageId = 0, array $recordData = array()); $tf->createTemplate($pageId, array $recordData = array()); $pageUid = $tf->createFakeFrontEnd($pageUid = 0); $tf->discardFakeFrontEnd(); $groupUid = $tf->createFrontEndUserGroup(array $recordData = array()); $userUid = $tf->createFrontEndUser($groups = , array $recordData = array()); $tf->logoutFrontEndUser(); $tf->loginFrontEndUser($userId);$userUid = $tf->createAndLoginFrontEndUser($groups = , array $recordData = array()); $isLoggedIn = $tf->isLoggedIn();
  • The testing framework can fake almost everything
  • The testing framework can fake almost everything $recordUid = $tf->createBackEndUser(array $recordData = array());
  • The testing framework can fake almost everything $recordUid = $tf->createBackEndUser(array $recordData = array()); $recordUid = $tf->createBackEndUserGroup(array $recordData = array());
  • The testing framework can fake almost everything
  • The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = test.txt, $content = );
  • The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = test.txt, $content = );$path = $tf->createDummyZipArchive($fileName = test.zip, array $filesToAdd = array());
  • The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = test.txt, $content = );$path = $tf->createDummyZipArchive($fileName = test.zip, array $filesToAdd = array()); $tf->deleteDummyFile($fileName);
  • The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = test.txt, $content = );$path = $tf->createDummyZipArchive($fileName = test.zip, array $filesToAdd = array()); $tf->deleteDummyFile($fileName); $path = $tf->createDummyFolder($folderName);
  • The testing framework can fake almost everything $path = $tf->createDummyFile($fileName = test.txt, $content = );$path = $tf->createDummyZipArchive($fileName = test.zip, array $filesToAdd = array()); $tf->deleteDummyFile($fileName); $path = $tf->createDummyFolder($folderName); $tf->deleteDummyFolder($folderName);