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
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’.
One Response
Junal Rahman
December 24th, 2007 at 3:05 pm
1great !!! this is what i was waiting to see for a long time …:)
RSS feed for comments on this post · TrackBack URI
Leave a reply