如何在 behat 中排除特定标记的 beforeFeature

How to exclude beforeFeature for specific tag in behat

我有一个带有特定标签的 behat 功能,我有两个 beforeFeature 功能。其中一个 运行 用于每个场景,其中一个 运行 仅用于特定的标记场景。问题是没有标签的 beforeFeature 也在那些有标签的特征之前 运行s。我想让这个 beforeFeature 在具有特定标签的那些功能上不 运行s。 例如,我有以下功能:

@taggedFeature
Feature: This feature runs tagged beforeFeature

在我的 FeatureContect 中,我有以下 beforeFeature 函数

/** @BeforeFeature */
public static function beforeFeatureDefault()
{ 
 // Do something
}

 /** @BeforeFeature @taggedFeature*/
public static function beforeFeatureTagged()
{ 
 // Do something
}

我想要的是不 运行 我标记的特征之前的 beforeFeatureDefault() 函数。

您可以使用 ~:

排除标记的特征
/** @BeforeFeature ~@taggedFeature */
public static function beforeFeatureDefault() {
     echo 'beforeFeatureDefault()';
}

/** @BeforeFeature @taggedFeature */
public static function beforeFeatureTagged() {
     echo 'beforeFeatureTagged()';
}