Jon*_*han 6 node.js gruntjs cucumberjs
我正在使用CucumberJS在我的NodeJS Web应用程序上运行测试.
目前,我可以通过执行grunt或仅执行CucumberJS任务来运行我的所有grunt任务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']);
};
Run Code Online (Sandbox Code Playgroud)
我终于找到了一个似乎足够好的解决方案,基于tags。
所以对于我的每个功能文件,我都添加了一个标签。
例如,对于Favorite.feature:
@favourite
Feature: Favourite
As a user of the system
I would like to favourite items
Run Code Online (Sandbox Code Playgroud)
然后我使用了一个GruntJS 选项来指定我想通过命令行参数运行的标签。
我通过grunt.option()在我的 gruntfile 中调用来做到这一点:
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty',
tags: grunt.option('cucumbertags')
}
}
Run Code Online (Sandbox Code Playgroud)
所以现在我可以像这样从命令行运行 GruntJS:
grunt cucumberjs --cucumbertags=@favourite
Run Code Online (Sandbox Code Playgroud)
它只会运行带有@favourite 标签的功能。好极了!
| 归档时间: |
|
| 查看次数: |
4666 次 |
| 最近记录: |