开发者

CodeIgniter and SimpleTest -- How to make my first test?

I'm used to web development using LAMP, PHP5, MySQL plus NetBeans with Xdebug.

Now I want to improve my development, by learning how to use (A) proper testing and (B) a framework. So I have set up CodeIgniter, SimpleTest and the easy Xdebug add-in for Firefox. This is great fun because maroonbytes provided me with clear instructions and a configured setup ready for download. I am standing on the shoulders of giants, and very grateful.

I've used SimpleTest a bit in the past. Here is a the kind of thing I wrote:

<?php
require_once('../simpletest/unit_tester.php');
require_once('../simpletest/reporter.php');

class TestOfMysqlTransaction extends UnitTestCase {
  function testDB_ViewTable() {
    $this->assertEqual(1,1);   // a pseudo-test
  }
}
$test = new TestOfMysqlTransaction();
$test->run(new HtmlReporter())
?>

So I hope I know what a test looks like. What I can't figure out is where and how to put a test in m开发者_开发知识库y new setup. I don't see any sample tests in the maroonbytes package, and Google so far has led me to posts that assume unit testing is already functionally available. What do I do?


Edit:

If you are following the maroonbytes setup, just follow the instructions:

  1. Download the SimpleTest framework and extract the files into your @codeigniter directory.
  2. In both your main folder and your admin/application folder create a new folder called tests.
  3. Within the new tests folder setup additional folders called ‘models’, ‘views’, ‘controllers’, ‘libraries’ and ‘helpers’.

Any file ending in .php and with a UnitTestCase inside any of those folders, should be run. :)


First, tests must be named properly. To test a controller welcome placed in the file welcome.php a test is named welcome_controller_test.php and stored under tests/controllers/. For more, see this post.

Second, Xdebug's GET argument interferes with the test routine. See post just above, also this post.

Third, the stub test I posted needed two four lines deleted:

//require_once('../simpletest/unit_tester.php');
//require_once('../simpletest/reporter.php');
...
//$test = new TestOfMysqlTransaction();
//$test->run(new HtmlReporter())

I am making tests fairly happily now. CodeIgniter lets me create/maintain tests easily, so my goal of TDD looks reachable. My earlier attempts at TDD gave me the idea, but scratch PHP was just too barren for me to be effective (and we won't discuss VBA!).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜