codeception单元测试仅针对公共函数testMe运行

Tzo*_*Noy 0 php unit-testing codeception

我创建了一个代码单元测试:

<?php


use Something\SiteResultsHolder;

class ResultHolderTest extends \Codeception\TestCase\Test
{
   /**
    * @var \UnitTester
    */
    protected $tester;

    protected function _before()
    {
    }

    protected function _after()
    {
    }

    // tests
    public function testMe()
    {
        //this test run

    }

    public function checkLimit() {
       //this test doesn't run
    }
}
Run Code Online (Sandbox Code Playgroud)

我在终端中称呼它:

codecept run unit
Run Code Online (Sandbox Code Playgroud)

但唯一的测试调用是 - > testMe,它不运行 - > checkLimit

他们都是公开的.

当我进行验收测试时,所有公共方法都是不同的测试,但在这里似乎没有用.

我如何在那里添加测试?会被称为?

小智 5

根据PhpUnit 4.2文档(https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html):

测试是名为test*的公共方法.

或者,您可以在方法的docblock中使用@test注释将其标记为测试方法.

\Codeception\TestCase\Test延伸\Codeception\TestCase,延伸\PHPUnit_Framework_TestCase.

因此,您实际上正在使用PHPUnit.您可以使用phpunit文档作为参考(https://phpunit.de/manual/current/en/index.html).

在你的情况下:

public function testCheckLimit() {
}
Run Code Online (Sandbox Code Playgroud)

要么

/**
 * @test
 */
public function checkLimit() {
}
Run Code Online (Sandbox Code Playgroud)

应该管用