首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果在Cucumber JS中包含失败,则跳过要素文件

如果在Cucumber JS中包含失败,则跳过要素文件
EN

Stack Overflow用户
提问于 2019-08-21 08:25:12
回答 1查看 490关注 0票数 1

因此,如果我总共有4个测试,如果第一个测试失败,我希望在第一个测试中快速失败,然后我希望继续运行其他3个测试/功能文件。

它现在所做的,我不喜欢的是,一旦一个测试失败,它就会失败,并且不会运行任何其他功能文件。

有什么想法吗?

我在黄瓜选项中尝试过:

代码语言:javascript
复制
'fail-fast': true

,但如果出现故障,将停止执行。

EN

回答 1

Stack Overflow用户

发布于 2020-04-16 12:01:39

如果您想要跳过功能文件中的其余测试,一旦该文件中的测试失败,则需要执行以下操作:

在每个要素文件的顶部,添加一个类似于@feature_<something unique>.

  • Add a Before After
  1. 的标记,以跟踪标记并确定某个要素是否出现故障:

代码语言:javascript
复制
// a place to track all of the failed scenarios.
const failedFeatures = [];

// identifies the feature tag using the pickle object.
function getFeature(pickle) {
    return pickle.tags.map(i => i.name).filter(i => i.indexOf('@feature_') === 0)[0];
}

// determines if the feature has failed, if it has then skip this test.
Before(function ({ pickle }) {
    const feature = getFeature(pickle);
    if (failedFeatures.indexOf(feature) >= 0) {
        return 'skipped';
    }
});

// if a test has failed, record that this feature has also failed.
After(function ({ pickle, result }) {
    const feature = getFeature(pickle);
    if (result.status === 'failed') {
        failedFeatures.push(feature);
    }
});

现场演示:https://testjam.io/?p=CW0qadImXwzRUTLLgvJY

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57582998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档