如何跳过 Codeception cest 测试

问题描述 投票:0回答:6

我只想跳过代码接收 cest 测试中的一项测试。

使用 Cept 测试,您可以执行

$scenario->skip();
但不适用于 Cest 测试。

所以我想做这样的事情。运行第一个测试,但跳过第二个测试。

Class MyTests{

   public funtion test1(){
    // My test steps
     }

   public function test2(){
     $scenario->skip("Work in progress");
     }
}

提前谢谢您。

php testing skip codeception
6个回答
31
投票

您正在寻找的方法称为“不完整”。

$scenario->incomplete('your message, why skipping');

如果你想在Cest文件中使用场景,你可以通过测试方法的第二个参数来获取它:

class yourCest 
{
    public function yourTest(WebGuy $I, $scenario) 
    {
        $scenario->incomplete('your message');
    }
}

或者您可以使用

$scenario->skip('your message')

class yourCest 
{
    public function yourTest(WebGuy $I, $scenario) 
    {
        $scenario->skip('your message');
    }
}

编辑:

正如已经提到的,WebGuy 已经过时了,注释

@skip
@incomplete
是您应该在 Cest 文件中跳过测试的方式。

class yourCest 
{

    /**
     * @skip Skip message
     */
    public function yourTest(AcceptanceTester $I) 
    {
        $I->shouldTestSomething();
    }
}

27
投票

我在单元测试中使用

skip
注释。

/**
 * @skip
 */
public function MyTest(UnitTester $I)
{
    ...
}

4
投票

首先,请记住,您可以使用哪些命令将取决于您加载的模块和套件。例如,如果您正在使用默认启用 WordPress 的 YML 进行集成测试:

$scenario->skip('your message');

无法在开箱即用的 Cest 或测试中工作,但可以在验收中工作。

事实上,通常这个命令适用于 Cept 测试 [Cept 通常是像测试那样的 Acceptance,Cests 和 Tests 通常是像 OOP 测试那样的 PHPUnit]。另外,您需要将 $scenario 传递给您的函数。这没有明确记录,我无法让它在 Cests 中工作。别让我开始说选择“$scenario”作为 BDD 框架的关键字是多么糟糕! “场景”是 Gherkin 中的一个关键字,指的是 Codeception 中的“步骤对象”。在 Codeception 中,它似乎被用作“环境”的冗余形式,尽管已经存在环境、套件和组。与这个伟大框架的大部分内容一样,文档和函数名称需要由英语为母语的人第二次重做! [还记得“网络人”吗?该死的欧洲人性别歧视者!哈哈]。

如果您使用

/**
 * @skip
 */
public function myTest(){
  //this test is totally ignored
}

Cest 或测试中函数正上方的注释将被跳过,甚至不会出现在报告中。 [真的跳过它]。如果您想完全隐藏测试,请使用此功能。

如果直接使用 PHPUnit 命令:

public function myTest(){
  throw new \PHPUnit_Framework_SkippedTestError('This test is skipped');
  //this test will appear as a yellow “skipped” test in the report
}

这将在报告中生成跳过的测试,并在 HTML 报告中变成黄色 [--html]。如果您想跳过测试但在报告中注意到它已被跳过,请使用此选项。


1
投票

使用 PHPUnit_Framework_SkippedTestError。例如:

    if (!extension_loaded('mongo')) {
        throw new \PHPUnit_Framework_SkippedTestError(
            'Warning: mongo extension is not loaded'
        );
    }

0
投票

因此,要在测试运行期间跳过您的场景:

  1. 您必须将 $scenario 作为测试中的第二个输入参数
  2. 拨打电话:$scenario->skip();
  3. 跳过后拨打电话:$I->comment(“场景跳过的原因”)

0
投票

如果您使用 Codeception V4 和 PHPUnit V9,可以使用以下代码:

public function test1(ApiTester $apiTester){
  $apiTester->markTestSkipped("Skiping reason message");

}

或者:

public function test1(ApiTester $apiTester){
  $apiTester->markTestIncomplete("reason message");

}
© www.soinside.com 2019 - 2024. All rights reserved.