Automated Unit Testing and Continuous Integration

  • Published on
    11-Feb-2017

  • View
    707

  • Download
    3

Transcript

AUTOMATED TESTS WITH PHPUNITIS A PUZZLE.CONTINUOUS INTEGRATION IS THEMISSING PIECEsachityoungInnovationshttps://github.com/sachit-singhhttp://yipl.com.np/AUTOMATED 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.comhttp://devopsreactions.tumblr.com/post/124056070020/when-a-bug-you-fixed-gets-re-introducedMartin Fowler's Test Pyramidsource http://martinfowler.comhttp://martinfowler.com/bliki/TestPyramid.htmlhttp://martinfowler.com/bliki/TestPyramid.htmlHOW 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 AVAILABLE....like..phpunitphpspeccodeceptionsimpletestphpunit is the most popular and the de facto unit testingframework in PHPsource Googlehttps://www.google.com/trends/explore#q=Phpunit%2C%20phpspec%2C%20codeception%2C%20simpletestgreen 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 featureshttps://app.shippable.com/WHAT 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 red...you go and buy titauraCULTUREsource http://geshan.com.nphttp://geshan.com.np/blog/2015/05/software-engineering-practices-in-nepal-infographics-part-4-includes-project-management/ENCOURAGEEXPLORE...THANKspecially geshan daiHELPINCITEMENThttp://sachit-singh.github.io/kswsbs/?print-pdfthank you

Recommended

View more >