mvc结构中的phpunit
我刚刚在我的 ubuntu 上安装了 phpunit。
现在我不想在我的(php 代码)mvc 结构中实现一些测试。但我不知道在哪里获得测试的输出...
我的控制器函数如下所示:
public function run_test(){
error_log("i was called correctly");
$mytest = new modeltest();
$mytest->run();
// $this->outputvar = testresults ??
$this->set_template("mytestview");
}
以及我的 testmodel:
class ModelTest extends PHPUnit_Framework_TestCase{
public function testWorks(){
error_log("i was called correctly as well");
$model = new model();
$this->assertEquals(3, $model->works(2, 1));
}
}
Works 只是一个用于测试 phpunit 运行的简单函数,它添加了两个值。
我如何获得测试结果?
i have just installed phpunit on my ubuntu.
now i wan't to implement some tests into my (php code) mvc structur. but i don't have any clue where i get the output of the test ...
i have controller function which looks like this:
public function run_test(){
error_log("i was called correctly");
$mytest = new modeltest();
$mytest->run();
// $this->outputvar = testresults ??
$this->set_template("mytestview");
}
as well as my testmodel:
class ModelTest extends PHPUnit_Framework_TestCase{
public function testWorks(){
error_log("i was called correctly as well");
$model = new model();
$this->assertEquals(3, $model->works(2, 1));
}
}
works is just a simple function for testing phpunit running, which adds two values.
how do i get the results of the test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是您运行 PHPUnit 测试的方式。参见PHPUnit手册第5章
换句话说,测试过程应该分开来自您的应用程序(因此您不需要自己的控制器)。命令行
phpunit
工具会为您完成所有脏活。 NetBeans IDE(也许还有其他)还允许您从 IDE 中运行此工具。THat's not how you're supposed to run PHPUnit's tests. See chapter 5 in PHPUnit manual
In other words, testing process should be separated from your application (so you do not need your own controller for that). A command line
phpunit
tool does all the dirty job for you. NetBeans IDE (and maybe others) also allow you to run this tool from within the IDE.我将继续假设您正在使用最新版本的 PHPUnit 并从命令行运行它。如果您想要测试的输出,测试运行程序提供了一些用于存储输出的选项:
这些选项来自 PHPUnit 文档。如果您只指定一个文件名,它会将输出存储在您运行测试的目录中。
I'm going to go ahead and assume you're using the latest version of PHPUnit and are running it from the command line. If you want the output of the test, the test runner offers a few choices for storing output:
These are from the PHPUnit docs. If you just specify a file name it will store the output within the directory you're running the tests from.
在 Ubunutu 上快速安装(以防万一)
,然后转到您的测试所在的文件夹:
@Mchl 将您链接到文档
Quick install on Ubunutu (just in case)
then go to the folder where your test is:
and @Mchl linked you to the documentation