Automated Unit Testing and Continuous Integration

  • Published on

  • View

  • Download


AUTOMATED TESTS WITH PHPUNITIS A PUZZLE.CONTINUOUS INTEGRATION IS THEMISSING PIECEsachityoungInnovations UNIT TESTINGTHE "WHAT"- just code testing another code-- means using an automation tool to execute your test suite--- a process using software tools to execute pre-scriptedtests on an application before releasing into productionTHE "WHY"- manual testing of all work flows, all scenarios andeverything else is time and cost consuming-- doesn't require human intervention--- increases speed and accuracy of test execution---- a lot of code coverageTYPES OF TESTS - MAINLYUnit Tests Functional Tests Integration Tests UNIT TESTStesting a small independent part of codedatabase independentminimal or no file system dependenceisolateddeterministicso it is fastWHY UNIT TESTS ?find problems early in the dev cyclethey facilitate changethey are good documentationsits fun..source http://devopsreactions.tumblr.com Fowler's Test Pyramidsource http://martinfowler.com DO WE WRITE UNIT TESTS?setup everything for testingmock dependencies??MOCKERYphp mock object framework for mocking dependenciesWHY MOCKERY?can mock static methods, unlike Prophecyintegrates easily with PHPUnitHOW DO WE WRITE UNIT TESTS?setup everything for testingmock dependenciestrigger the method being testedverify the results, that they are correctclassExampleClassextendssomeClass{protected$personpublicfunction__construct(Person$person){$this>person=$person}publicfunctioncreate(array$details){return$this>person>create($details)}}classexampleTestextendssomeTestCase{protected$personpublicfunctionsetup(){parent::setUp()$this>person=\Mockery::mock('\Person')$this>exampleClass=newExampleClass($this>person)}publicfunctiontearDown(){parent::tearDown()m::close()}}publicfunctiontestItShouldCreateAPerson(){$this>person>shouldReceive('create')>once()>with(['name'=>'HisName','age'=>30])>andReturnSelf()$this>assertInstanceOf('\Person',$this>exampleClass>create(['name'=>'HisName','age'=>30]))}publicfunctiontearDown() unit tests..??how do we write GOODstructure is importantconsistent namingmock everything you needand write code that can be mockedtestable codereadable teststest and verify only one specific part (single unit of work)self sufficiencyLOT OF TESTING FRAMEWORKS is the most popular and the de facto unit testingframework in PHPsource Google is goodred is notTHE MISSING PIECEContinuous Integrationa development practice that requires developers tointegrate code several times a dayallowing teams to detect problems earlyeach push is verified by an automated buildthe goal is to provide rapid feedback incase a defect isintroducedCI is important because....ensures on a continuous basis that you have a workingproducthelp detect bugs very earlyLOT OF SERVICESWHY ?SHIPPABLEit's free for private reposupports dockerhas unlimited buildsa lot of other cool features DOES IT DO?pulls changes from your repo and runs a build every timeyou push anythingnotify you of the success/failure of the buildyou can even set it to notify you on hipchatshippable.ymlTO DO IT- set up a couple of configurations- choose what to do and whenyour push turns out go and buy titauraCULTUREsource geshan daiHELPINCITEMENT you


View more >