Previous Up Next
Recommended Tools RSD RSDEngine - The Rapid and Secure Development Engine

UnitTests

Quality Assurance

Introduction

All test suites for a version of a project must be in $RSD_DIRECTORY/projects/$PROJECT_NAME/$VERSION/unitTests/. The file index.php in that directory lists all available test suites. All files starting with an uppercase letter are regarded as test suites for PHPUnit. Their name is handed to runUnitTest.php which executes the test suite. All files starting with a lowercase letter are not regarded as a test suite for PHPUnit. These files can perform any tests you like. Please note that all files containing a test suite class for PHPUnit must be named like the class (just with .php appended). Please see http://pear.php.net/manual/en/package.php.phpunit.php for more information on PHPUnit.

Creating a PHPUnit Test Suite

For the static class RSStringUtil we would create a file named RSStringUtilTest.php (note that the first letter is uppercase!) and implement the following test suite in it:


1 <?php
2 /**TestSuite for RSStringUtil
3 * This class must be implemented in the file RSStringUtilTest.php.
4 */
5 class RSStringUtilTest extends PHPUnit_TestCase {
6
7 function RSStringUtilTest($name)
8 {
9 $this->PHPUnit_TestCase($name);
10 }
11
12 function setUp()
13 {
14 //do nothing; its a static class!
15 }
16
17 function testRemoveTrailingString1()
18 {
19 $result = RSStringUtil::removeTrailingString('This is:cool', 'cool');
20 $expected = 'This is:';
21 $this->assertEquals($expected, $result);
22 }
23
24 function testRemoveTrailingString2()
25 {
26 $result = RSStringUtil::removeTrailingString('This is:cool', '');
27 $expected = 'This is:cool';
28 $this->assertEquals($expected, $result);
29 }
30
31 function testRemoveTrailingString3()
32 {
33 $result = RSStringUtil::removeTrailingString('', '');
34 $expected = '';
35 $this->assertEquals($expected, $result);
36 }
37
38 function testRemoveLeadingString1()
39 {
40 $result = RSStringUtil::removeLeadingString('This is:cool', 'This is:');
41 $expected = 'cool';
42 $this->assertEquals($expected, $result);
43 }
44
45 function testRemoveLeadingString2()
46 {
47 $result = RSStringUtil::removeLeadingString('This is:cool', '');
48 $expected = 'This is:cool';
49 $this->assertEquals($expected, $result);
50 }
51
52 function testRemoveLeadingString3()
53 {
54 $result = RSStringUtil::removeLeadingString('', '');
55 $expected = '';
56 $this->assertEquals($expected, $result);
57 }
58
59 function testBytesToKiloBytes1()
60 {
61 $result = RSStringUtil::bytesToKiloBytes(1024*1024);
62 $expected = '1024';
63 $this->assertEquals($expected, $result);
64 }
65
66 function testBytesToKiloBytes2()
67 {
68 $result = RSStringUtil::bytesToKiloBytes(2000,6);
69 $expected = '1.953125';
70 $this->assertEquals($expected, $result);
71 }
72
73 function testLimit1()
74 {
75 $result = RSStringUtil::limit('This is my text that is too long', 10, '**');
76 $expected = 'This is my**';
77 $this->assertEquals($expected, $result);
78 }
79
80 function testLastIndexOf1()
81 {
82 $result = RSStringUtil::lastIndexOf('This is my text, my everything', 'my');
83 $expected = '17';
84 $this->assertEquals($expected, $result);
85 }
86
87 function testLastIndexOf2()
88 {
89 $result = RSStringUtil::lastIndexOf('This is my text, my everything', 'not there');
90 $expected = false;
91 $this->assertTrue($expected === $result);
92 }
93
94 function testLastIndexOf3()
95 {
96 $result = RSStringUtil::lastIndexOf('This is my text, my everything', 'This');
97 $expected = 0;
98 $this->assertTrue($expected === $result);
99 }
100 }
101 ?>

Creating a Simple Test Suite

If possible implement PHPUnit test suites! In some cases this is not appropriate. 'simple' test suites can be directly executed by clicking the corresponding link displayed by index.php. A 'simple' test suite must be stored in a file starting with a lowercase letter.

Previous Up Next
Recommended Tools RSD RSDEngine - The Rapid and Secure Development Engine

Documentation generated on Mon, 8 Dec 2003 13:09:51 +0100 by phpDocumentor 1.2.3