几天前,我开始为我的函数做一些单元测试,但是我真的找不到如何为这个函数做正确的测试。我觉得这很简单,但我错过了一些东西。
/**
* Tests model->function()
*/
public function testFunction() {
// TODO Auto-generated model->testFunction()
$this->markTestIncomplete ( "function test not implemented" );
$this->model->testFunction('', '5');
$this->model->testFunction('test', '');
$this->model->testFunction('test', 'a');
$this->model->testFunction('1', '5');
}这就是我所拥有的,phpUnit忽略了这些测试。我想要的是测试我的函数(它需要两个参数,两个整数)并检查:
有谁能帮我一下吗?
非常感谢!
发布于 2014-01-15 23:29:33
第一次发言
$this->markTestIncomplete ()将导致PHPUnit传递该测试文件,并在输出中用i标记它,以避免未完成(执行)。
其次,测试的格式是不正确的。您需要创建对象,然后测试它。
public function setUp()
{
$this->model = new model();
}
public function testFunction()
{
$this->assertEquals('test', $this->model->Function(5)); // Test what the function should return, using parameters replacing the 5
}该函数应该根据我在您的尝试中看到的内容接受一个参数。然后,这个函数将返回一些内容,您可以对其进行评估。
可以选择使用dataProvider为测试提供多个值,并查看输出。有关更多信息,请查看PHPUnit手册。
https://stackoverflow.com/questions/21143388
复制相似问题