CodeIgniter和SimpleTest - 如何使我的第一个测试? [英] CodeIgniter and SimpleTest -- How to make my first test?

查看:135
本文介绍了CodeIgniter和SimpleTest - 如何使我的第一个测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于使用LAMP,PHP5,MySQL加上带有Xdebug的NetBeans进行web开发。

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

现在我想通过学习如何使用A)适当的测试和(B)一个框架。所以我设置了CodeIgniter,SimpleTest和Firefox的 easy Xdebug 加载项。这很有趣,因为 maroonbytes 向我提供了清楚的说明和已配置的设置准备下载。我站在巨人的肩膀上,非常感激。

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.

我过去使用SimpleTest。这是一种我写的东西:

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())
?>

所以我希望我知道测试的样子。我不知道是什么地方和如何在我的新设置进行测试。我在maroonbyte包中没有看到任何样本测试,Google到目前为止已经导致我的帖子,假设单元测试已经在功能上可用。我该怎么办?

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 my 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?

推荐答案

首先,测试必须正确命名。要测试控制器欢迎放在文件welcome.php中,测试名为 welcome_controller_test.php ,并存储在tests / controllers /下。有关详情,请参见此帖

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.

其次,Xdebug的GET参数干扰了测试例程。请参见上面的信息,此帖

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())

现在测试相当愉快。 CodeIgniter允许我轻松地创建/维护测试,所以我的TDD目标看起来可达。我早些时候在TDD的尝试给了我想法,但是暂时的PHP只是太荒谬,我不能有效(我们不会讨论VBA!)。

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!).

这篇关于CodeIgniter和SimpleTest - 如何使我的第一个测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆