我使用CucumberJS在我的NodeJS web应用程序上运行测试。
目前,我可以通过执行grunt,或者只执行CucumberJS任务,使用grunt cucumberjs来运行所有繁重的任务。
但现在我只想执行特定的功能。
例如,假设我有以下特性文件:
我希望只运行最喜欢的特性测试,使用如下命令:
grunt cucumberjs Favourite
这个是可能的吗?
顺便说一下,这是我的gruntfile.js
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
...
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty'
}
}
});
...
grunt.loadNpmTasks('grunt-cucumber');
grunt.registerTask('default', [... 'cucumberjs']);
};发布于 2014-02-04 05:21:16
我终于找到了一种基于标签的解决方案,这个解决方案似乎很有效。
因此,对于我的每个功能文件,我都添加了一个标记。
例如,对于Favourite.feature:
@favourite
Feature: Favourite
As a user of the system
I would like to favourite items然后,我使用了一个GruntJS选项来指定要通过命令行参数运行的标记。
我通过我的gruntfile中的grunt.option()调用实现了这一点:
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty',
tags: grunt.option('cucumbertags')
}
}现在,我可以从命令行运行GruntJS,如下所示:
grunt cucumberjs --cucumbertags=@favourite而且它将只运行带有@业余标签的特性。耶!
发布于 2014-06-05 07:30:23
下面是我的任务,允许您通过feature.name进行过滤:
https://github.com/webforge-labs/cuked-zombie/blob/master/tasks/cucumber.js (将其下载到“任务”文件夹中,您可以用:grunt.loadTasks('tasks')加载它)
像这样配置它(Gruntfile.js):
grunt.loadNpmTasks('grunt-cucumber');
grunt.initConfig({
cucumberjs: {
// config for all features when called with: `grunt cucumber`
all: {
src: 'features',
options: {
steps: "tests/js/cucumber/bootstrap.js",
format: "pretty"
}
},
// config for single features when called with `grunt --filter some-feature`
features: {
src: 'features',
options: {
steps: "tests/js/cucumber/bootstrap.js",
format: "pretty"
}
}
}
});用它来搭配:
grunt cucumber --filter post它将运行post.feature (在功能目录中的某个位置)
使用新的黄瓜-js版本,可以通过特性行:https://github.com/cucumber/cucumber-js/pull/168运行它。
发布于 2020-03-13 20:21:53
我还没有用grunt测试过它,但是haven可以选择在不修改gherkin文件的情况下执行场景。只需调用cucumber-js --name "Scenario Name",因此我假设发送相同的参数来授予它将完成它的工作。
https://stackoverflow.com/questions/21544441
复制相似问题