Writing inline unit test makes it painless and hassle free. Orchid comes with a bundled unit test library which you can take full advantage of. Have a look at the following code to understand how to write your unit tests. No more “setup” and “teardown” for you :D

Lets consider your controller is app/controllers/ut.php

<?
class ut extends controller 
{
	function base()
	{
		$this->use_view=false;
		$name = "Orchid";
		unittest::assertContains("Orchid",$name);
 
		$gmap = $this->library->gmap;
		$location = $gmap->getGeoCode("dhaka");
 
		$longitude = $location['lon'];
		$lattitude = $location['lat'];
 
		unittest::assertEqual($lattitude,"23.709801");
		unittest::assertEqual($longitude,"23.709801");
	}
}
?>

Now point your broswer to http://your_orchid_path/ut/base/unittest. You have to write “unittest” at the end to view the output of test cases from inline unit tests. Otherwise it will work as regular action and no unit test result will be displayed in output. Nice, huh?

Now see what it generates as a result of these assertions

Test passed in Method: base. Line: 8. File: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\orchid\app\controllers\ut.php.
Expected: Haystack has a needle named ‘Orchid’, Actual: Haystack has a needle named ‘Orchid’.


Test passed in Method: base. Line: 16. File: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\orchid\app\controllers\ut.php.
Expected: 23.709801, Actual: 23.709801.


Test failed in Method: base. Line: 17. File: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\orchid\app\controllers\ut.php.
Expected: 23.709801, Actual: 90.407112.