加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHPUnit测试函数在类之外

发布时间:2020-12-13 18:14:52 所属栏目:PHP教程 来源:网络整理
导读:我是 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(
我是 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’,以便将它们识别为测试.

From the documentation:

  1. 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 );
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读