Top Banner
AUTOMATED TESTS WITH PHPUNIT IS A PUZZLE. CONTINUOUS INTEGRATION IS THE MISSING PIECE sachit youngInnovations
34

Automated Unit Testing and Continuous Integration

Feb 11, 2017

Download

Software

bsscht
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Automated Unit Testing and Continuous Integration

AUTOMATED TESTS WITH PHPUNITIS A PUZZLE.

CONTINUOUS INTEGRATION IS THEMISSING PIECE

sachityoungInnovations

Page 2: Automated Unit Testing and Continuous Integration

AUTOMATED UNIT TESTING

Page 3: Automated Unit Testing and Continuous Integration

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

Page 4: Automated Unit Testing and Continuous Integration

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

Page 5: Automated Unit Testing and Continuous Integration

TYPES OF TESTS - MAINLY

Unit Tests

Functional Tests

Integration Tests

Page 6: Automated Unit Testing and Continuous Integration

UNIT TESTS

testing a small independent part of code

database independent

minimal or no file system dependence

isolated

deterministic

so it is fast

Page 7: Automated Unit Testing and Continuous Integration

WHY UNIT TESTS ?find problems early in the dev cycle

they facilitate change

they are good documentations

its fun..

Page 9: Automated Unit Testing and Continuous Integration

Martin Fowler's Test Pyramid

source http://martinfowler.com

Page 10: Automated Unit Testing and Continuous Integration

HOW DO WE WRITE UNIT TESTS?setup everything for testing

mock dependencies

??

Page 11: Automated Unit Testing and Continuous Integration

MOCKERYphp mock object framework for mocking dependencies

Page 12: Automated Unit Testing and Continuous Integration

WHY MOCKERY?

can mock static methods, unlike Prophecy

integrates easily with PHPUnit

Page 13: Automated Unit Testing and Continuous Integration

HOW DO WE WRITE UNIT TESTS?setup everything for testing

mock dependencies

trigger the method being tested

verify the results, that they are correct

Page 14: Automated Unit Testing and Continuous Integration

class ExampleClass extends someClass protected $person;

public function __construct(Person $person) $this­>person = $person;

public function create(array $details) return $this­>person­>create($details);

Page 15: Automated Unit Testing and Continuous Integration

class exampleTest extends someTestCase protected $person; public function setup() parent::setUp(); $this­>person = \Mockery::mock('\Person'); $this­>exampleClass = new ExampleClass($this­>person);

public function tearDown() parent::tearDown(); m::close();

Page 16: Automated Unit Testing and Continuous Integration

public function testItShouldCreateAPerson() $this­>person ­>shouldReceive('create') ­>once() ­>with(['name' => 'HisName', 'age' => 30]) ­>andReturnSelf();

$this­>assertInstanceOf('\Person', $this­>exampleClass­>create( ['name' => 'HisName', 'age' => 30]) );

public function tearDown()

Page 17: Automated Unit Testing and Continuous Integration

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

Page 18: Automated Unit Testing and Continuous Integration

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

self sufficiency

Page 19: Automated Unit Testing and Continuous Integration

LOT OF TESTING FRAMEWORKS AVAILABLE....

Page 20: Automated Unit Testing and Continuous Integration

like..

phpunit

phpspec

codeception

simpletest

Page 21: Automated Unit Testing and Continuous Integration

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

source Google

Page 22: Automated Unit Testing and Continuous Integration

green is good

Page 23: Automated Unit Testing and Continuous Integration

red is not

Page 24: Automated Unit Testing and Continuous Integration

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

Page 25: Automated Unit Testing and Continuous Integration

CI is important because....

ensures on a continuous basis that you have a workingproduct

help detect bugs very early

Page 26: Automated Unit Testing and Continuous Integration

LOT OF SERVICES

Page 27: Automated Unit Testing and Continuous Integration

WHY ?SHIPPABLEit's free for private repo

supports docker

has unlimited builds

a lot of other cool features

Page 28: Automated Unit Testing and Continuous Integration

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

Page 29: Automated Unit Testing and Continuous Integration

shippable.yml

TO DO IT

- set up a couple of configurations

- choose what to do and when

Page 30: Automated Unit Testing and Continuous Integration
Page 31: Automated Unit Testing and Continuous Integration

your push turns out red...

you go and buy titaura

CULTURE

Page 33: Automated Unit Testing and Continuous Integration

ENCOURAGE

EXPLORE

...

THANK

specially geshan dai

HELP

INCITEMENT

Page 34: Automated Unit Testing and Continuous Integration

thank you