# Create a PHP unit test case using SimpleTest

You can download SimpleTest at [https://sourceforge.net/projects/simpletest/](https://sourceforge.net/projects/simpletest/)

Suppose you have a <span class="caps">PHP</span> file called <tt>math.php</tt> that contains functions that you want to test.

```
<?function square($x) {	return $x * $x;}function cube($x) {	return $x * $x * $x;}?>
```

Then you can write a test case in another file, say <tt>mathtest.php</tt>.

(Suppose you have downloaded and extracted SimpleTest to <tt>C:\\simpletest</tt>.)

```
<?phpif (!defined('SIMPLE_TEST')) {	define('SIMPLE_TEST', 'C:\\simpletest\\');}require_once(SIMPLE_TEST . 'unit_tester.php');require_once(SIMPLE_TEST . 'reporter.php');require_once('math.php');class TestOfLogging extends UnitTestCase {	function TestOfLogging() {		$this->UnitTestCase();	}	function testSquare() {		$this->assertEqual(16, square(4));	}}$test = &new TestOfLogging();$test->run(new TextReporter());?>
```

(Each function named test\* in this class represents a test case and will be run automatically by SimpleTest.)

Run the test case with the command <tt>php mathtest.php</tt>. As the <tt>square</tt> function is written correctly, the test case will pass.

```
testofloggingOKTest cases run: 1/1, Passes: 1, Failures: 0, Exceptions: 0
```

Try changing the <tt>square</tt> function and see what happens.