qa:testfesttalk

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
qa:testfesttalk [2009/03/18 19:42] dabaseqa:testfesttalk [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== PHPT roundup talk ====== ====== PHPT roundup talk ======
-This wikipage contains all extra information for the talk prepared for phptestfest 2009. They heavily rely on content written by other people before. Every resource of the talk, even the slides (in different formats) will be in this place. Other testfesters can use and modify this talk to save precious time.+This wikipage contains all extra information for the talk prepared for [[qa:testfest-2009|phptestfest 2009]]. They heavily rely on content written by other people before. Every resource of the talk, even the slides (in different formats) will be in this place. Other testfesters can use and modify this talk to save precious time. 
 + 
 +[[http://tinyurl.com/c9bqf4]] 
  
 ===== How is PHP Tested ===== ===== How is PHP Tested =====
Line 13: Line 15:
   * a text editor   * a text editor
   * a way to execute the code   * a way to execute the code
 +
 +Required Packages (debian) 
 +
   * the make commando available    * the make commando available 
-  * bison or flex +  * autoconf 
 +  * gcc 
 +  * flex-old  
 +  * libxml2-dev 
 +  * re2c 
 +  * Bison (before php 5.2)  
 +  * lcov / ggcov 
  
  
Line 98: Line 110:
  
 ===== Execute tests ===== ===== Execute tests =====
 +There is a set of things that need to be prepared before you can actually start execute the tests. 
 +
 +==== Which "php" executable "make test" look for ====
 +You must use TEST_PHP_EXECUTABLE environment variable to explicitly select the php executable to be used to run the tests. That can either be the CLI or CGI executable. Command "make test" executes "run-tests.php" script with "php" binary.  Some test scripts such as session must be executed by CGI SAPI. Therefore, you must build PHP with CGI SAPI to perform all tests.
 +
 +
 +<code>
 +TEST_PHP_EXECUTABLE=sapi/cli/php
 +</code>
 +and 
 +<code>
 +export TEST_PHP_EXECUTABLE
 +</code>
  
 ==== All Tests ==== ==== All Tests ====
 +You can re-run the same Tests as executed in ''make test'' when you execute the file run-tests.php
  
-==== Single Test ==== +<code> 
-===== Write Tests... =====+php run-tests.php 
 +</code> 
 + 
 +==== Single Tests ==== 
 +It is possible to execute a single test or tests residing in one directory. Again run-tests.php helps here.  
 + 
 +A single Test 
 +<code> 
 +php run-tests.php tests/func/test010.phpt 
 +</code> 
 + 
 +A directory with tests  
 +<code> 
 +php run-tests.php tests/func/ 
 +</code> 
 + 
 +===== Write Tests ===== 
 +From here on it's easy to add own tests.  
 + 
 +<code> 
 +--TEST-- 
 +Hello world test 
 +--FILE-- 
 +<?php 
 +echo "Hello"; 
 +?> 
 +--CLEAN-- 
 +--EXPECT-- 
 +Hello 
 +</code> 
 + 
 +===== Write good Tests... =====
 There are certain guidelines you can follow when writing tests. There are several guidelines that you can follow to get working test code that is solid and makes sense.  There are certain guidelines you can follow when writing tests. There are several guidelines that you can follow to get working test code that is solid and makes sense. 
 +Several basics apply in general 
 +
 +  * KISS Keep the Test short in general. 
 +  * Test one functionality at a time 
 +  * Try to make execute the test fast, waiting for the next eclipse to proof the date() function fails will slow down build times 
 +  * Document the outcome. People using your tests will not always be experts for that specific tests 
 +  * Place Links to resources as they help understand the test. A test is as much about documentation as on prooving fail or working condition of a function
 +    * Extension docs 
 +    * Bug reports 
 +  * If you are testing on a bug, make sure you got the bottom line of it
  
 ==== Mystery Guests  ==== ==== Mystery Guests  ====
Line 140: Line 207:
 Examples:  Examples: 
  
-  * Files in /tmp+  * Files in /tmp (there is no /tmp in windows) 
 +  * extensions installed 
 +  * Special variants/setups of extensions installed
  
 Avoid By Avoid By
   * Write Setup Code for the resource   * Write Setup Code for the resource
 +  * Do not re-use resources through multiple tests 
 +
 +==== Test Run Wars ====
 +
 +//Such wars arise when the tests run fine as long as you are 
 +the only one testing but fail when more programmers run 
 +them. This is most likely caused by resource interference: 
 +some tests in your suite allocate resources such as tempo- 
 +rary files that are also used by others. Apply Make Re- 
 +source Unique (3) to overcome interference. 
 +//
 +
 +Examples: 
 +  * Creating files in a public directory (/tmp/ if choosen right ^^) under a fixed file name 
 +
 +Avoid by: 
 +  * Adding Random or user based Value to file name
 +
 +==== Eager Test ====
 +
 +//When a test method checks several methods of the object to 
 +be tested, it is hard to read and understand, and therefore 
 +more difficult to use as documentation. Moreover, it makes 
 +tests more dependent on each other and harder to maintain. 
 +The solution is simple: separate the test code into test 
 +methods that test only one method using Fowler’s Extract 
 +Method (F:110), using a meaningful name highlighting the 
 +purpose of the test. Note that splitting into smaller methods 
 +can slow down the tests due to increased setup/teardown 
 +overhead.// 
 +
 +Examples:
 +  * Tests of different behaviour in one test
 +  * More than one method is tested 
 +
 +Avoid
 +  * Split into several smaller tests
 +
 +
  
  
qa/testfesttalk.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1