Test logiciel : Passé, Présent, Futur (Forum PHP)

Test logiciel : Passé, Présent, Futur (Forum PHP)

Le test logiciel est devenu une importante préoccupation au cours de ces dernières années. Tout le monde souhaite écrire des tests et des outils se sont développés pour aider à cela. Victoire ? Pas tout à fait.
Cette présentation fait l'état du test en PHP en présentant les outils d'hier et d'aujourd'hui et se termine par une ouverture sur les nouvelles techniques de tests. Mêlant théorie et pragmatisme, vous serez également sensibilisés à l'écriture de tests pour vos applications PHP.

Online slides: http://slides.williamdurand.fr/sofware-testing-past-present-future/
Sources: https://github.com/willdurand-slides/sofware-testing-past-present-future

F59d2f1ed66b8d9c6ceebea5a748494b?s=128

William Durand

October 23, 2014
Tweet

Transcript

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

    2014
  2. 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).
  3. Past /pɑːst/

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

  5. Tools, tools, tools

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

  7. Extend It! ® etsy/phpunit‑extensions

  8. 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
  9. 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
  10. More? Wanna use PHPUnit with Prophecy and Atoum asserters? ®

    hautelook/frankenstein
  11. vfsStream Mocking file system since 2007. ® mikey179/vfsStream

  12. 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() ); } }
  13. Tests As Documentation

  14. 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
  15. 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
  16. phpspec Spec BDD since , yep! 2007 class MarkdownSpec extends

    ObjectBehavior { function it_converts_plain_text_to_html_paragraphs() { $this->toHtml("Hi, there")->shouldReturn("<p>Hi, there</p>"); } } ® phpspec/phpspec
  17. Hooray!? Not really.

  18. Present /ˈpreznt/

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

  20. Testing, In Parallel ® (Ruby tool!) ® ® grosser/parallel brianium/paratest

    liuggio/fastest
  21. Continuous Integration

  22. Record & Replay

  23. 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
  24. Gor HTTP traffic replication tool, written in Go. ® buger/gor

  25. It is not only about testing your code.

  26. But rather, testing everything.

  27. Security Testing , automatic SQL injection tool , security scanner

    sqlmap Zapr SensioLabs Security Checker
  28. Web Acceptance Testing

  29. 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
  30. ® jlipps/sausage

  31. Fuzzy Testing

  32. gremlins.js ® marmelab/gremlins.js

  33. But also Infrastructure Testing Smoke Testing ( ) Robustness Testing

    Actually,  Testing smoke.sh
  34. Future /ˈfjuːtʃəʳ/

  35. Testing will be... Automated! More formal

  36. Disclaimer The following techniques are not really "new" from a

    research point of view.
  37. Model‑based Testing

  38. None
  39. 1 Model w N Implementations

  40. Model ¿ yEd Graph Editor

  41. 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
  42. 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.
  43. Sikuli y F http://www.sikuli.org/

  44. Results

  45. Automated Model Generation Story of my life.

  46. Contract‑based Testing

  47. 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
  48. Recap' Congrats for understanding the need for testing Testing is

    more than using existing tools Test automation is part of your future, start now!
  49. Thank You. Questions? è ¾ ® ¬ joind.in/11953 williamdurand.fr github.com/willdurand

    twitter.com/couac