在 Behat 中,有没有办法测试特定标签?
in Behat, Is there a way to test for a specific tag?
我的 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
}
@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
...
我的 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
}
@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
...