Node.js 如何使用GruntJS运行一个特定的CucumberJS功能?
我正在使用CucumberJS在我的NodeJS web应用程序上运行测试 目前,我可以通过执行Node.js 如何使用GruntJS运行一个特定的CucumberJS功能?,node.js,gruntjs,cucumberjs,Node.js,Gruntjs,Cucumberjs,我正在使用CucumberJS在我的NodeJS web应用程序上运行测试 目前,我可以通过执行grunt来运行我的所有grunt任务,或者使用grunt CucumberJS仅运行CucumberJS任务 但现在我只想执行特定的功能 例如,假设我有以下功能文件: 签名特征 最喜欢的功能 我只想使用以下命令运行喜爱的功能测试: 咕噜黄瓜 这可能吗 顺便说一句,这是我的grunfile.js: 'use strict'; module.exports = function(grunt) {
grunt
来运行我的所有grunt任务,或者使用grunt CucumberJS
仅运行CucumberJS任务
但现在我只想执行特定的功能
例如,假设我有以下功能文件:
- 签名特征
- 最喜欢的功能
咕噜黄瓜
这可能吗
顺便说一句,这是我的grunfile.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']);
};
我终于想出了一个解决方案,似乎工作得足够好,基于
因此,对于我的每个功能文件,我都添加了一个标记
例如,对于favorite.feature:
@favourite
Feature: Favourite
As a user of the system
I would like to favourite items
然后,我使用了一个参数来指定我希望通过命令行参数运行的标记
我通过在GrunFile中调用grunt.option()
来实现这一点:
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty',
tags: grunt.option('cucumbertags')
}
}
现在我可以从命令行运行GruntJS,如下所示:
grunt cucumberjs --cucumbertags=@favourite
它将只运行带有@Favorite标记的功能。耶 这是我的任务,允许您按功能进行筛选。名称:
(将其下载到“任务”文件夹中,您可以使用:grunt.loadTasks('tasks')
)
按如下方式配置(Gruntfile.js):
将其用于:
grunt cucumber --filter post
它将运行post.feature(功能目录中的某个地方)
使用新的cucumber js版本,可以按功能行运行:
我没有用grunt测试它,但是cucumber有一个选项,可以在不修改gherkin文件的情况下执行场景。只需调用cumberjs--name“Scenario name”
,因此我假设发送相同的参数来授予它将完成它的工作
grunt cucumber --filter post