Автотесты всего — — — — — Монитор качества Кроссбраузерные тесты Unit-тесты Restful API-тесты UI-тесты Затраты на развитие проекта bitbucket.org/articul/articul.checklist — Автобекап — Open Graph теги — Ядро в .gitignore ... — 39 пунктов — 13 автотестов Unit-тесты www.PHPUnit.de // ApiToolsTest.php class ApiToolsTest extends PHPUnit_Framework_TestCase { public function testSomething() { /* .. */ } } public function testMakeFileUrl() { $_SERVER["SERVER_NAME"] = "domain.com"; $this->assertEquals( http://domain.com/upload/file.xml, ApiTools::makeFileUrl( "upload/file.xml" ) ); } There was 1 failure: 1) ApiToolsTest::testMakeFileUrl Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'http://domain.com/upload/file.xml' +'domain.com/upload/file.xml' /failover/httpdocs/local/tests/classes/ApiToolsTest.php:17 FAILURES! Tests: 1, Assertions: 1, Failures: 1. dev$ /opt/phpunit/vendor/bin/phpunit --testdox -c local/tests/phpunit.xml PHPUnit 3.7.38 by Sebastian Bergmann. Configuration read from /failover/httpdocs/local/tests/phpunit.xml ApiTools [x] Make file url TDD уверенность в коде // local/tests/bootstrap.php define("BX_NO_ACCELERATOR_RESET", true); define("NO_KEEP_STATISTIC", true); define("NO_AGENT_STATISTIC", true); define("NO_AGENT_CHECK", true); define("NOT_CHECK_PERMISSIONS", true); $_SERVER["DOCUMENT_ROOT"] = dirname(dirname(__DIR__)); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; Restful API Guzzle / Buzz use GuzzleHttp\Client; class RestfulTest extends PHPUnit_Framework_TestCase { protected $client; public function setUp() { $this->client = new Client([ "base_url" => "http://api.domain.com/" ]); } } public function testGetBooks() { $json = $this->client->get("books/")->json(); $bookId = intval($json["books"][0]["id"]); $this->assertGreaterThan( 0, $bookId ); return $bookId; } @depends /** * @depends testGetBooks */ public function testGetBookPersons($bookId) { $json = $this->client->get( "book/{$bookId}/persons/” )->json(); $this->assertTrue( $json["persons"]["0"]["id"] > 0 ); } @expectedException try / catch // component if (count($arResult["persons"]) <= 0) { throw new ApiException("No persons found", 404); } /** * @expectedException Exception * @expectedExceptionCode 404 */ public function testGetBookPersonsNotFound() { $this->client->get("book/INVALID_ID/persons/"); } Рефакторинг без страха Use case тестирование вручную UI-тесты Selenium Webdriver — Selenium Server + Webdriver http://docs.seleniumhq.org http://selenium2.ru — Firefox — Facebook PHP-Webdriver https://github.com/facebook/php-webdriver — PHPUnit protected function setUp() { $this->driver = RemoteWebDriver::create( "http://192.168.0.123:4444/wd/hub", array( WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::FIREFOX ) ); } $this->driver->get($this->baseUrl); $input = $this->driver->findElement( WebDriverBy::cssSelector("input[name='email']") ); $input->sendKeys("valid@test.email"); $form = $this->driver->findElement( WebDriverBy::cssSelector("form[name='subscribe']") ); $form->submit(); // wait for AJAX do { sleep(1); } while ($this->driver->executeScript( "return jQuery.active" )); $isSuccess = $this->driver->executeScript( "return $('div.success').is(':visible')" ); // take screenshot if (!$isSuccess) { $fileName = $this->screenshotFolder . $this->getName() . ".png"; $this->driver->takeScreenshot( $fileName ); } — — — — Работа с DOM Выполнение JavaScript AJAX Screenshot Самообразование побочный эффект от написания тестов — — — — — Articul.Checklist BrowserStack PHPUnit Rest API тесты Selenium Webdriver Константин Лех facebook.com/k.s.lekh