Date post: | 18-Dec-2014 |
Category: |
Technology |
Upload: | pierre-joye |
View: | 1,413 times |
Download: | 0 times |
TestFest 2009PHP Netherland, Utrecht
Pierre Joye
Welcome to the TestFest 2009!
Thanks you for joining us!
First tests fest?
First test (I won’t tell your boss)?
What should I bother?
PHP needs YOU
You need PHP too
a broken PHP is uselessA new Phpet is waiting for you!
What is this about?
Improve code coverage
Fantastic opportunity to be part of PHP
Network to learn and work together
PHPT
Single test in a single .phpt file
Small set of similar tests in a .phpt file
Each test are run by calling a new php instance
Test isolationCustom configuration Support of segfaults and other fatal
errors
Testing PHP, everything (or less)
(n)make test
make test \TESTS=/home/joe/php/ext/reflection/tests
make test \TESTS=/home/joe/php/ext/a/tests/b.phpt
Naming convention
A bugbug12345.phpt (bug.php.net/12345)
Features<functionname>_basic.phpt
Errors<functionname>_error.phpt
Generalextname<test nr>.phpt
Simplest test ever
--TEST—Not testing PHP--FILE—Goede morgen--EXPECT—Goede morgen
2nd most simplest test ever (failing)
--TEST—Let try to test echo!--FILE—<?php echo “Hoe doet u?”; ?>--EXPECT—Ik heb nodig koffie
Expect using printf syntax
--TEST—rand--FILE—<?php echo “rand: ”. rand(); ?>--EXPECT—rand: %d
Expect using regex syntax (avoid it)
--TEST—rand--FILE—<?php echo “rand: ”. rand(); ?>--EXPECTREGEX—M_E: 2.718281[0-9]*
Where to find the EXPECTF placeholders list
http://qa.php.net/expectf_details.php
Custom ini settings
--TEST—Timezone--INI—date.timezone=Europe/Berlin--FILE—<?php echo date_timezone_get(); ?>--EXPECT—Europe/Berlin
Conditional test
--TEST—Timezone--SKIPIF—<?php if (! extension_loaded (‘myext’) die(‘myext not available’); ?>
--FILE—…--EXPECT—..
Render unto Caesar the things which are Caesar’s
--TEST—Timezone--CREDITS—John TheWriter#testfest Utrecht 2009--FILE—…--EXPECT—..
Complete doc about phpt (with samples!)
http://qa.php.net/phpt_details.php
What is a good test?
Keep it smalll and beautifulTest one feature per phptAvoid large output
What is a good test?
If a large output is necessaryNumerate or name each line
Easier to analyzeEasier to debug
Resources
PHP GCOV - Test and Code Coverage Analysishttp://gcov.php.net/
PHP WIKI - How to look at the test coverage for an extensionhttp://wiki.php.net/qa/testcoverage
PHP QA - Writing Testshttp://qa.php.net/write-test.php
Lessons Learned from PHPT Writinghttp://wiki.php.net/qa/phptlessonslearned
PHP CVS - README.TESTINGhttp://cvs.php.net/viewvc.cgi/php-src/README.TESTING