The*_*mlt 8 php phpunit unit-testing
我是PHPUnit和单元测试的新手,所以我有一个任务:我可以在类之外测试一个函数:
    function odd_or_even( $num ) {
    return $num%2; // Returns 0 for odd and 1 for even
}
class test extends PHPUnit_Framework_TestCase {
    public function odd_or_even_to_true() {
        $this->assetTrue( odd_or_even( 4 ) == true );
    }
}
现在它只是返回:
No tests found in class "test".
Dou*_*ngs 13
您需要在函数名称前加上'test',以便将它们识别为测试.
- 测试是名为test*的公共方法.
或者,您可以在方法的docblock中使用@test注释将其标记为测试方法.
呼叫应该没问题odd_or_even().
例如:
class test extends PHPUnit_Framework_TestCase {
    public function test_odd_or_even_to_true() {
        $this->assertTrue( odd_or_even( 4 ) == true );
    }
}
| 归档时间: | 
 | 
| 查看次数: | 6266 次 | 
| 最近记录: |