首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHPUnit只识别我四个测试中的三个

PHPUnit只识别我四个测试中的三个
EN

Stack Overflow用户
提问于 2018-09-26 14:50:01
回答 1查看 22关注 0票数 0

我有一个包含四个单元测试的课程。这门课看起来如下:

代码语言:javascript
复制
class TestWorkflowService extends TestCase
{
    private $containerMock;

    private $workflowEntityMock;

    private $workflowService;

    public function setup()
    {
        $this->containerMock = $this->createMock(ContainerInterface::class);
        $this->workflowService = new WorkflowService($this->containerMock);
        $this->workflowEntityMock = $this->createMock(WorkflowInterface::class);
    }

    public function testGetWorkflowProcessByEntityNullResult()
    {
        self::assertNull($this->workflowService->getWorkflowProcessByEntity($this->workflowEntityMock));
    }

    public function testGetProcessHandlerByEntityNullResult()
    {
        self::assertNull($this->workflowService->getProcessHandlerByEntity($this->workflowEntityMock));
    }

    public function testRestartWorkflow()
    {
        $modelStateMock = $this->createMock(ModelState::class);
        $processHandlerMock = $this->createMock(ProcessHandler::class);
        $processHandlerMock->method('start')->willReturn($modelStateMock);
        $this->containerMock->method('get')->willReturn($processHandlerMock);
        self::assertNull($this->workflowService->restartWorkflow($this->workflowEntityMock));
    }

    public function setEntityToNextWorkflowState()
    {
        $modelStateMock = $this->createMock(ModelState::class);
        $processHandlerMock = $this->createMock(ProcessHandler::class);
        $processHandlerMock->method('start')->willReturn($modelStateMock);
        $this->containerMock->method('get')->willReturn($processHandlerMock);
        self::assertNull($this->workflowService->setEntityToNextWorkflowState($this->workflowEntityMock));
    }
}

..。但是当我运行PHPUnit时,我得到了这样的结果:

3/3 (100%) 时间: 2.17秒,内存: 5.75MB 确定(3次测试,3次断言)

为什么我的第四次考试不被认可?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-26 14:52:35

PHPUnit使用下列规则标识测试方法。

这些测试是名为test*的公共方法。 或者,您可以使用方法文档块中的@test注释将其标记为测试方法。

这样您就可以在测试类中使用其他公共方法,而不必将它们解释为测试(虽然我不知道为什么要这样做)。

将您的方法名更改为testSetEntityToNextWorkflowState,或者用@test注释标记它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52520572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档