我正在练习BDD使用cucmber.js写一些单元测试。 当我尝试使用'And'语句时。错误显示
TypeError: Add is not a function
这是我的代码
.feature
Feature: dataTable
Scenario Outline: <a> + <b> + <c> = <answer>
Given I had number <a>
And I add another number <b>
When I add with <c>
Then I got answer <answer>
Examples:
|a|b|c|answer|
|1|2|3|6|
|10|15|25|50|
.stepDefinition
defineSupportCode(function({Given,When,Then,And}){
let ans = 0;
Given('I had number {int}', function(input){
ans = input
})
And('I add another number {int}',function(input){
ans += input
})
When('I add with {int}',function(input){
ans += input
})
Then('I got answer {int}', function(input){
assert.equal(ans,input)
})
})
,错误信息如下:
TypeError: Add is not a function
at ... // my file location
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test_cucumber@1.0.0 cucumber: `cucumber.js ./test/e2e/Features -r ./test/e2e/StepDefinition`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test_cucumber@1.0.0 cucumber script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/lab1321_mac_air/.npm/_logs/2018-01-04T08_15_28_568Z-debug.log
我想知道我是否写错了。谢谢!
答案 0 :(得分:1)
And
和But
是功能文件的语法糖 - 换句话说,它们是Given
,When
和Then
的别名。
在定义步骤时,您应该使用Given
,When
和Then
来描述步骤尝试实现的目标(先决条件,行动或结果),然后,如果您有多个先决条件,操作或结果,请仅在功能文件中使用And
或But
。