Slide 1

Slide 1 text

Software Testing: Past, Present, Future William Durand ‑ October 23rd, 2014

Slide 2

Slide 2 text

Software Testing is the process of executing a program or system with the intent of finding errors. However, "testing shows the presence, not the absence of bugs" (Dijkstra).

Slide 3

Slide 3 text

Past /pɑːst/

Slide 4

Slide 4 text

Testing was... Expensive ($$$) Time consuming Complicated

Slide 5

Slide 5 text

Tools, tools, tools

Slide 6

Slide 6 text

PHPUnit by Sebastian Bergmann © ® sebastianbergmann/phpunit (Alternative: ) atoum/atoum

Slide 7

Slide 7 text

Extend It! ® etsy/phpunit‑extensions

Slide 8

Slide 8 text

Mockery class MockeryTest extends \PHPUnit_Framework_TestCase { public function testGetsAverageTemperatureFromThreeServiceReadings() { $service = \Mockery::mock('service'); $service ->shouldReceive('readTemp') ->times(3) ->andReturn(10, 12, 14); $temperature = new Temperature($service); $this->assertEquals(12, $temperature->average()); } } ® padraic/mockery

Slide 9

Slide 9 text

Prophecy $prophet = new Prophecy\Prophet(); $prophecy = $prophet->prophesize(); $prophecy->willExtend('stdClass'); $dummy = $prophecy->reveal(); // fake $prophecy->read(Argument::type('string')); $fake = $prophecy->reveal(); // stub $prophecy->read('123')->willReturn('value'); $stub = $prophecy->reveal(); // mock $prophecy->read()->shouldBeCalled(); // spy $prophecy->read()->shouldHaveBeenCalled(); ® phpspec/prophecy

Slide 10

Slide 10 text

More? Wanna use PHPUnit with Prophecy and Atoum asserters? ® hautelook/frankenstein

Slide 11

Slide 11 text

vfsStream Mocking file system since 2007. ® mikey179/vfsStream

Slide 12

Slide 12 text

Example class VfsStreamTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $this->cacheDir = vfsStream::setup('cache'); $this->repository = new YamlUserRepository( vfsStream::url('cache/users.yml') ); } public testAddSerializesUserIntoYaml() { $this->repository->add(new User('John', 'Doe')); $this->assertEquals( '- { first_name: "John", last_name: "Doe" }', $this->cacheDir->getChild('users.yml')->getContent() ); } }

Slide 13

Slide 13 text

Tests As Documentation

Slide 14

Slide 14 text

TestDox class EmailParserTest extends \PHPUnit_Framework_TestCase { public function testReadsSimpleBody() { ... } public function testRecognizesDateStringAboveQuote() { ... } public function testDoesNotModifyInputString() { ... } public function testDealsWithMultilineReplyHeaders() { ... } } y $ phpunit --testdox EmailReplyParser\Tests\Parser\EmailParser [x] Reads simple body [x] Recognizes date string above quote [x] Does not modify input string [x] Deals with multiline reply headers F , Dan North (2006) Introducing BDD

Slide 15

Slide 15 text

Behat Story BDD since . 2010 Feature: ls In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ ® Behat/Behat

Slide 16

Slide 16 text

phpspec Spec BDD since , yep! 2007 class MarkdownSpec extends ObjectBehavior { function it_converts_plain_text_to_html_paragraphs() { $this->toHtml("Hi, there")->shouldReturn("

Hi, there

"); } } ® phpspec/phpspec

Slide 17

Slide 17 text

Hooray!? Not really.

Slide 18

Slide 18 text

Present /ˈpreznt/

Slide 19

Slide 19 text

Testing is... Slow Manual But, trending (hype?)

Slide 20

Slide 20 text

Testing, In Parallel ® (Ruby tool!) ® ® grosser/parallel brianium/paratest liuggio/fastest

Slide 21

Slide 21 text

Continuous Integration

Slide 22

Slide 22 text

Record & Replay

Slide 23

Slide 23 text

PHP•VCR class PhpVcrTest extends \PHPUnit_Framework_TestCase { /** * @vcr unittest_annotation_test */ public function testInterceptsWithAnnotations() { // Requests are intercepted and stored into: // `tests/fixtures/unittest_annotation_test` $content = file_get_contents('http://google.com'); $this->assertEquals('some content', $content); // VCR is automatically turned on and off } } ® php‑vcr/php‑vcr

Slide 24

Slide 24 text

Gor HTTP traffic replication tool, written in Go. ® buger/gor

Slide 25

Slide 25 text

It is not only about testing your code.

Slide 26

Slide 26 text

But rather, testing everything.

Slide 27

Slide 27 text

Security Testing , automatic SQL injection tool , security scanner sqlmap Zapr SensioLabs Security Checker

Slide 28

Slide 28 text

Web Acceptance Testing

Slide 29

Slide 29 text

Mink $driver = new \Behat\Mink\Driver\GoutteDriver(); $session = new \Behat\Mink\Session($driver); $session->start(); $session->visit('http://williamdurand.fr'); echo "Status code: ". $session->getStatusCode() . "\n"; echo "Current URL: ". $session->getCurrentUrl() . "\n"; $page = $session->getPage(); $anchorEl = $page->find('css', 'h3 a.title'); ® Behat/Mink

Slide 30

Slide 30 text

® jlipps/sausage

Slide 31

Slide 31 text

Fuzzy Testing

Slide 32

Slide 32 text

gremlins.js ® marmelab/gremlins.js

Slide 33

Slide 33 text

But also Infrastructure Testing Smoke Testing ( ) Robustness Testing Actually,  Testing smoke.sh

Slide 34

Slide 34 text

Future /ˈfjuːtʃəʳ/

Slide 35

Slide 35 text

Testing will be... Automated! More formal

Slide 36

Slide 36 text

Disclaimer The following techniques are not really "new" from a research point of view.

Slide 37

Slide 37 text

Model‑based Testing

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

1 Model w N Implementations

Slide 40

Slide 40 text

Model ¿ yEd Graph Editor

Slide 41

Slide 41 text

Code Generation public interface Login { public void e_Init(); public void v_ClientNotRunning(); public void e_StartClient(); public void v_LoginPrompted(); public void e_ValidPremiumCredentials(); public void v_Browse(); } ¿ GraphWalker

Slide 42

Slide 42 text

Interaction With The SUT public class SimpleTest extends ExecutionContext implements Login { @Override public void e_Init() { ... } ... @Test public void runSmokeTest() { ... } @Test public void runFunctionalTest() { ... } } ¿ Java/JUnit, Robotium, Selenium, Appium, etc.

Slide 43

Slide 43 text

Sikuli y F http://www.sikuli.org/

Slide 44

Slide 44 text

Results

Slide 45

Slide 45 text

Automated Model Generation Story of my life.

Slide 46

Slide 46 text

Contract‑based Testing

Slide 47

Slide 47 text

Praspel The missing specification language for PHP. /** * @requires t : array([to integer()],boundinteger(5,10)) and * i : integer(); * @ensures \result : boolean(); * @throwable FooException */ public function find($t, $i) { // ... } ® hoaproject/Praspel

Slide 48

Slide 48 text

Recap' Congrats for understanding the need for testing Testing is more than using existing tools Test automation is part of your future, start now!

Slide 49

Slide 49 text

Thank You. Questions? è ¾ ® ¬ joind.in/11953 williamdurand.fr github.com/willdurand twitter.com/couac