【问题标题】:codeception unit tests run only for public function testMe代码接收单元测试仅针对公共函数 testMe 运行
【发布时间】:2014-08-31 13:47:37
【问题描述】:

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

<?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
    }
}

我在终端中调用它:

codecept run unit

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

它们都是公开的。

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

如何在那里添加测试?会被调用吗?

【问题讨论】:

    标签: php unit-testing codeception


    【解决方案1】:

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

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

    或者,您可以在方法的文档块中使用@test 注解将其标记为测试方法。

    \Codeception\TestCase\Test 扩展 \Codeception\TestCase,扩展 \PHPUnit_Framework_TestCase

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

    在你的情况下:

    public function testCheckLimit() {
    }
    

    /**
     * @test
     */
    public function checkLimit() {
    }
    

    应该工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      相关资源
      最近更新 更多