我正在使用 CucumberJS 在我的 NodeJS 网络应用程序上运行测试。
目前,我可以通过执行 grunt
来运行我所有的 grunt 任务,或者使用 grunt cucumberjs
只运行 CucumberJS 任务。
但现在我只想执行特定功能。
例如,假设我有以下功能文件:
- 登录功能
- 最喜欢的功能
我只想运行最喜欢的功能测试,使用如下命令:
grunt cucumberjs 最爱
这可能吗?
顺便说一句,这是我的 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']);
};
最佳答案
基于 tags,我终于找到了一个似乎运行良好的解决方案.
因此,对于我的每个功能文件,我都添加了一个标签。
例如,对于 Favourite.feature:
@favourite
Feature: Favourite
As a user of the system
I would like to favourite items
然后我使用了 GruntJS option通过命令行参数指定我想运行的标签。
我通过在我的 grunt 文件中调用 grunt.option()
来做到这一点:
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty',
tags: grunt.option('cucumbertags')
}
}
所以现在我可以像这样从命令行运行 GruntJS:
grunt cucumberjs --cucumbertags=@favourite
它只会运行带有@favourite 标签的功能。耶!
关于node.js - 如何使用 GruntJS 运行一个特定的 CucumberJS 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21544441/