Slide 1

Slide 1 text

Michael Bodnarchuk BEYOND TESTING

Slide 2

Slide 2 text

WHO AM I ● Michael Bodnarchuk @davert ● Web-developer from Kyiv, Ukraine ● Lead developer of Codeception testing framework and other OS tools like: Robo, AspectMock, etc

Slide 3

Slide 3 text

WHAT IS IT ALL ABOUT ● What to do when PHPUnit is installed and first tests are done ● What you should know writing a test ● Choosing the best tool for testing ● Creating test environment

Slide 4

Slide 4 text

KINDS OF TESTS ● Acceptance ● Functional ● Integration ● Unit

Slide 5

Slide 5 text

BEST PRACTICES SOME KIND OF

Slide 6

Slide 6 text

IDEAL TEST ▪Condition (Given) ▪Action (When) ▪Assertion (Then)

Slide 7

Slide 7 text

HOW TO WRITE TEST ● Separate configuration from test ● Do not use hierarchy for testcases (use traits when needed) ● Separate test code from support code ● Make test simple and verbose

Slide 8

Slide 8 text

DON'T DO IT THIS WAY move to configuration use traits

Slide 9

Slide 9 text

IMPLEMENT YOUR OWN ASSERTIONS custom assertions make code more readable

Slide 10

Slide 10 text

MAKE IT SIMPLER!

Slide 11

Slide 11 text

WHAT IS HARD TO TEST ● Asynchronous stuff ● Remote Services ● Real Data

Slide 12

Slide 12 text

TESTS CRITERIA ● Execution Stability ↓ ● Stability to Changes ↑ ● Speed ↓ ● Coverage ↑ ● Preciseness ↓ ● Readability ↕ Unit => Integration => Functional => Acceptance

Slide 13

Slide 13 text

PRICE OF A FAULT REGRESSION TESTS

Slide 14

Slide 14 text

DATA MANAGEMENT HOW TO TEST DB INTERACTION

Slide 15

Slide 15 text

MANAGING TEST DATA WITH ● Fixtures (nelmio/alice) ● Dumps ● Factories (thephpleague/factory-muffin)

Slide 16

Slide 16 text

FACTORY_MUFFIN IN REAL LIFE

Slide 17

Slide 17 text

DATA CLEANUP STRATEGIES ● Manually create/delete data between tests ● Recreate the database between tests ● Using transactions – reverting changes with rollback

Slide 18

Slide 18 text

TOOLS FOR TESTING YOU SHOULD PROBABLY KNOW

Slide 19

Slide 19 text

PHPUNIT ● Standard de-facto ● Monolithic framework ● Two mocking engines included (why not 3?) ● JUnit, HTML, reports... and codecoverage ● And other 100500 sometimes used features

Slide 20

Slide 20 text

PHPSPEC ● TDD framework ● Classes are generated from tests ● Dependencies are described through mocking ● Does not replace PHPUnit ● For development, not for testing

Slide 21

Slide 21 text

BEHAT ● BDD-framework ● Ubiquitous language (Gherkin) ● Acceptance testing via Mink (Selenium, Goutte, etc)

Slide 22

Slide 22 text

CODECEPTION ● BDD-style testing framework ● Scenario DSL for describing tests ● Over 20 modules to cover the most of possible cases ● Testing via Selenium, PhpBrowser, frameworks...

Slide 23

Slide 23 text

TESTING EMAILS: MAILCATCHER

Slide 24

Slide 24 text

MAILCATCHER ● Ruby application with web interface ● SMTP-mock ● Provides REST API for sent emails ● API can be used in tests ● Alternative in Go - MailHog

Slide 25

Slide 25 text

TESTING WEB APPLICATIONS ● Selenium ● PhantomJS ● Browser emulation via HTTP client

Slide 26

Slide 26 text

USING SELENIUM ON CI SERVER ● Selenium Server ● Xvfb – Virtual Framebuffer ● Firefox or Chromium

Slide 27

Slide 27 text

INSTEAD OF CONFIGURING IT MANUALLY docker run -d -p 4444:4444 -e APP_HOST=myapp davert/selenium-env

Slide 28

Slide 28 text

WHAT IS DOCKER? ● Docker is an open platform distributed apps ● Runs and manages isolated Linux containers ● Provides GitHub-like infrastructure

Slide 29

Slide 29 text

PARALLEL TESTING ● Tests separation ● Jobs isolation

Slide 30

Slide 30 text

HOW TO PARALLEL TESTS WITH DOCKER ● Build container(s) for test environment ● Run container(s) with Docker Compose ● Use Jenkins Matrix to run concurrent builds

Slide 31

Slide 31 text

docker run -i -t -v $WORKSPACE:/project test_container ./runtests.sh $SUITE

Slide 32

Slide 32 text

CONCLUSIONS ● Testing is not just about unit tests ● Tests are code: make them easy to read and maintain ● Testing is about tools, environment and infrastructure as well

Slide 33

Slide 33 text

QUESTIONS? ● My name is Michael Bodnarchuk ● Twitter: @davert ● GitHub: DavertMik ● ….and don't forget to try http://codeception.com