Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 98 lines (61 sloc) 2.656 kB
9004b37 @mapkyca Introducing the first commit of the simple test framework regression …
authored
1 Simple Test Framework - An example PHP Regression tester
2 by Marcus Povey <marcus@marcus-povey.co.uk>
3 ================================================================================
4
5 Introduction:
6 -------------
7
8 This is a simple regression testing tool which can be used to execute tests
9 against programs written in PHP.
10
11 It is primarily an example of how you might write a regression tester, but
12 hopefully it will be of use to someone out there.
13
14 Inspired by this blog post:
15 http://www.marcus-povey.co.uk/2011/12/05/regression-testing-if-you-dont-do-it-youre-a-fscking-idiot/
16
17 Adapted from the tester module in the BCT Platform which is (C) Marcus Povey 2010-11
18
19 Requirements:
20 -------------
21
22 This is a PHP command line application so you will require php5-cli and its
0895677 @Erkan-Yilmaz typo; correct file name
Erkan-Yilmaz authored
23 various dependencies.
9004b37 @mapkyca Introducing the first commit of the simple test framework regression …
authored
24
25 On Debian based systems this is a simple matter of:
26
27 sudo apt-get install php5-cli
28
29 Usage:
30 ------
31
32 php test.php [-p path/to/tests] [-t HelloWorldTest]
33
34 Example:
35 --------
36
37 To run all the tests in the sub directory /tests/
38
39 php test.php
40
41 To specify another directory to look in for tests
42
43 php test.php -p /path/to/my/tests
44
45 To run a specific test only, specify it by its CLASS NAME
46
47 php test.php -t MyClassTest
48
49 You can specify multiple tests to run...
50
51 php test.php -t MyClassTest -t AnotherTest
52
53 Writing your own tests:
54 -----------------------
55
0895677 @Erkan-Yilmaz typo; correct file name
Erkan-Yilmaz authored
56 Take a look at Example.test.php for an example test, but in a nutshell your
9004b37 @mapkyca Introducing the first commit of the simple test framework regression …
authored
57 test should extend and implement the Test class, e.g.
58
59 class FooTest extends Test
60 {
61 public function init() {
62
63 // Place your test initialisation code here
64 }
65
66 public function run() {
67
68 if (!sometest1()) // Execute a test
69 return TEST_FAIL; // One way of returning an error
70
71 if (!sometest2()) // Execute a test
72 throw Exception("All uncaught exceptions are caught by the tester, and their message echoed!"); // Another way to return an error.
73
74 if (!sometest3()) // Execute a test
75 return TEST_WARN; // A non fatal error, but none the less we want to let the user know about it.
76
77 return TEST_PASS; // Important! The engine will assume a failure unless you say it all went ok!
78 }
79
80 public function destroy() {
81 // Place your test cleanup code here.. close/delete files, destroy objects, shut sockets etc
82 }
83 }
84
85 Tip: Code using good OO techniques. Group common test functions into a class hierachy!
86
87 Log Entries
88 -----------
89
90 The Test class provides you with a number of methods to help you keep a log, these are
91
92 Test::log('message'); // Send a notice level message
93 Test::warning('message'); // Send a warning message
94 Test::error('message'); // Send an error message
95
96
97 Happy hacking!
Something went wrong with that request. Please try again.