我是
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".
您需要在函数名前加上’test’,以便将它们识别为测试.
- The tests are public methods that are named test*.
Alternatively,you can use the @test annotation in a method’s docblock to mark it as a test method.
调用odd_or_even()应该没问题.
例如:
class test extends PHPUnit_Framework_TestCase { public function test_odd_or_even_to_true() { $this->assertTrue( odd_or_even( 4 ) == true ); } }