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 PIECE

    sachityoungInnovations

    https://github.com/sachit-singhhttp://yipl.com.np/

  • AUTOMATED UNIT TESTING

  • THE "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 production

  • THE "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 coverage

  • TYPES OF TESTS - MAINLY

    Unit Tests

    Functional Tests

    Integration Tests

  • UNIT TESTS

    testing a small independent part of code

    database independent

    minimal or no file system dependence

    isolated

    deterministic

    so it is fast

  • WHY UNIT TESTS ?find problems early in the dev cycle

    they facilitate change

    they are good documentations

    its fun..

  • source http://devopsreactions.tumblr.com

    http://devopsreactions.tumblr.com/post/124056070020/when-a-bug-you-fixed-gets-re-introduced

  • Martin Fowler's Test Pyramid

    source http://martinfowler.com

    http://martinfowler.com/bliki/TestPyramid.htmlhttp://martinfowler.com/bliki/TestPyramid.html

  • HOW DO WE WRITE UNIT TESTS?setup everything for testing

    mock dependencies

    ??

  • MOCKERYphp mock object framework for mocking dependencies

  • WHY MOCKERY?

    can mock static methods, unlike Prophecy

    integrates easily with PHPUnit

  • HOW DO WE WRITE UNIT TESTS?setup everything for testing

    mock dependencies

    trigger the method being tested

    verify the results, that they are correct

  • classExampleClassextendssomeClass{protected$person

    publicfunction__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 GOOD

    structure is important

    consistent naming

    mock everything you need

    and write code that can be mocked

    testable code

    readable tests

  • test and verify only one specific part (single unit of work)

    self sufficiency

  • LOT OF TESTING FRAMEWORKS AVAILABLE....

  • like..

    phpunit

    phpspec

    codeception

    simpletest

  • phpunit is the most popular and the de facto unit testingframework in PHP

    source Google

    https://www.google.com/trends/explore#q=Phpunit%2C%20phpspec%2C%20codeception%2C%20simpletest

  • green is good

  • red is not

  • THE MISSING PIECEContinuous Integration

    a development practice that requires developers tointegrate code several times a day

    allowing teams to detect problems early

    each push is verified by an automated build

    the goal is to provide rapid feedback incase a defect isintroduced

  • CI is important because....

    ensures on a continuous basis that you have a workingproduct

    help detect bugs very early

  • LOT OF SERVICES

  • WHY ?SHIPPABLEit's free for private repo

    supports docker

    has unlimited builds

    a lot of other cool features

    https://app.shippable.com/

  • WHAT DOES IT DO?

    pulls changes from your repo and runs a build every timeyou push anything

    notify you of the success/failure of the build

    you can even set it to notify you on hipchat

  • shippable.yml

    TO DO IT

    - set up a couple of configurations

    - choose what to do and when

  • your push turns out red...

    you go and buy titaura

    CULTURE

  • source http://geshan.com.np

    http://geshan.com.np/blog/2015/05/software-engineering-practices-in-nepal-infographics-part-4-includes-project-management/

  • ENCOURAGE

    EXPLORE

    ...

    THANK

    specially geshan dai

    HELP

    INCITEMENT

    http://sachit-singh.github.io/kswsbs/?print-pdf

  • thank you

Recommended

View more >