Node.js 努力使用gherkin apickli为API获得一个简单的BDD测试套件

Node.js 努力使用gherkin apickli为API获得一个简单的BDD测试套件,node.js,cucumber,gherkin,web-api-testing,Node.js,Cucumber,Gherkin,Web Api Testing,我试图学习如何使用nodejsapickli模块为我的小黄瓜特性文件创建一个简单的工作步骤定义文件。如果我尝试做一个非常简单的概念验证连接到GithubAPI。下面是使用curl的API调用 curl -i https://api.github.com/users/marktyers/orgs 这将返回200的响应代码 我已经安装了cucumber和apickli: npm install --save-dev cucumber apickli 以下是我的文件结构: ├── index.js

我试图学习如何使用nodejsapickli模块为我的小黄瓜特性文件创建一个简单的工作步骤定义文件。如果我尝试做一个非常简单的概念验证连接到GithubAPI。下面是使用curl的API调用

curl -i https://api.github.com/users/marktyers/orgs
这将返回200的响应代码

我已经安装了
cucumber
apickli

npm install --save-dev cucumber apickli
以下是我的文件结构:

├── index.js
├── package.json
└── test
  └── features
    ├── step_definitions
    │   └── myapi.js
    └── test.feature
这是我的
test.feature
文件:

Feature:
  As a novice I want to test my BDD framework.

  Scenario: Retrieving an empty list should return a 200 code.
    Given I set Content-Type header to application-json
    When I GET https://api.github.com/users/marktyers/orgs
    Then response code should be 200
这是我的
myapi.js
文件

'use strict'

const apickli = require('apickli')

module.exports = function() {
  // cleanup before every scenario
  this.Before(function(scenario, callback) {
    this.apickli = new apickli.Apickli('http', 'httpbin.org')
    callback()
})
当我运行功能测试时,我得到:

Feature:

  As a novice I want to test my BDD framework.

  Scenario: Retrieving an empty list should return a 200 code.
  ? Given I set Content-Type header to application-json
  ? When I GET https://api.github.com/users/marktyers/orgs
  ? Then response code should be 200

Warnings:

  1) Scenario: Retrieving an empty list should return a 200 code. - test/features/todo.feature:5
    Step: Given I set Content-Type header to application-json - test/features/todo.feature:6
   Message:
     Undefined. Implement with the following snippet:

   Given('I set Content-Type header to application-json', function (callback) {
     // Write code here that turns the phrase above into concrete actions
     callback(null, 'pending');
   });

2) Scenario: Retrieving an empty list should return a 200 code. - test/features/todo.feature:5
  Step: When I GET https://api.github.com/users/marktyers/orgs - test/features/todo.feature:7
 Message:
   Undefined. Implement with the following snippet:

   When('I GET https://api.github.com/users/marktyers/orgs', function (callback) {
     // Write code here that turns the phrase above into concrete actions
     callback(null, 'pending');
   });

3) Scenario: Retrieving an empty list should return a 200 code. - test/features/todo.feature:5
 Step: Then response code should be 200 - test/features/todo.feature:8
 Message:
   Undefined. Implement with the following snippet:

   Then('response code should be {int}', function (int, callback) {
     // Write code here that turns the phrase above into concrete actions
     callback(null, 'pending');
   });

1 scenario (1 undefined)
3 steps (3 undefined)
0m00.000s

我知道我需要包括额外的步骤定义,但它们应该放在哪里,应该放在其中什么?

您很可能安装了cucumber js 2.x的最新版本,而不是1.x

apickli中的步骤定义是在旧版本中实现的,如果您使用的是cucumber js的最新版本2.x,则不会使用


npm安装-g黄瓜-js@1.3.3我们应该解决这个问题

您很可能安装了cucumber js 2.x的最新版本,而不是1.x

apickli中的步骤定义是在旧版本中实现的,如果您使用的是cucumber js的最新版本2.x,则不会使用


npm安装-g黄瓜-js@1.3.3我们应该解决这个问题

谢谢你,马特。有最新版本的文档吗?没有,很遗憾,很难找到任何关于最新版本的文档。我只从cucumberjs的发布文档中发现了cucumberjs,对于apickli,它没有提到它只与兼容cucumber@1.x,唯一的赠品是这些步骤的实施方式。这正是我们在JS/Node领域需要习惯的东西,而不是Java等等,所有的东西都记录得非常糟糕……谢谢Matt。有最新版本的文档吗?没有,很遗憾,很难找到任何关于最新版本的文档。我只从cucumberjs的发布文档中发现了cucumberjs,对于apickli,它没有提到它只与兼容cucumber@1.x,唯一的赠品是这些步骤的实施方式。这正是我们在JS/Node领域需要习惯的东西,而不是Java等等,所有的东西都记录得非常糟糕。。。