在Behat中,有没有办法测试特定的标签?

时间:2016-08-23 16:52:46

标签: behat

我的FeatureContext.php中有一个函数,它使用@AfterScenario来清理测试期间创建的虚假数据库条目。我想在特定场景中添加@debug标记,告诉函数如果标记存在,则不删除为该场景创建的条目。

/**
 * Deletes the records created during the scenarios.
 * @AfterScenario
 */
public function cleanDB(AfterScenarioScope $scope)
{
    // if !@debug present
        // delete files from database
    // end if
}

1 个答案:

答案 0 :(得分:1)

@ lauda的回答让我很接近,我想出了其余部分。

我使用了Behat场景对象的hasTag()函数。

/**
 * Deletes the NCP records created during the scenarios.
 * @AfterScenario
 */
public function cleanDB(AfterScenarioScope $scope)
{
    // if the @debug tag is set, ignore
    if (!$scope->getScenario()->hasTag("debug")) {
        // delete records from database
    }
}

如果我用@debug装饰场景,我可以测试它并改变我的功能。

@debug
Scenario: do the thing
  ...
相关问题