我正在构建一个Backbone应用程序,需要进行自动化测试。我不喜欢在自动化测试中使用硒。
我正在研究Jasmine和Cucumber.js。我认为Jasmine可能更好,但在我工作的公司,他们使用黄瓜进行服务器端测试,我正在调查Cucumber.js是否可以用于生产。
有什么建议吗?
Cucumber.js非常稳定,可以在生产中使用。与Cucumber ruby相比,它缺少一些高级功能,比如场景轮廓和(现在可用)转换。有关开发状态表,请参阅自述文件。
它可以与Zombie.js、Phantom.js、Selenium一起使用,甚至可以在浏览器中使用。实际上,您可以在Cucumber步骤定义中使用任何断言/测试库。
正如Andreas所指出的,Jasmine是针对单元测试/规范的,而Cucumber是一个验收测试工具(涉及整个应用程序堆栈)。
如果您在开始使用Cucumber.js时需要帮助,请随时ping我(@jbpros在Twitter上,jbpro在Freenode/#Cucumber上)。
我没有足够的分数给@jbpros答案添加注释,但需要注意的是,场景大纲现在已经在cucumber.js中完成了,如下所述。
例如:
世界:
// features/support/world.js
var zombie = require('zombie');
var World = function World(callback) {
this.browser = new zombie(); // this.browser will be available in step definitions
this.visit = function(url, callback) {
this.browser.visit(url, callback);
};
callback(); // tell Cucumber we're finished and to use 'this' as the world instance
};
exports.World = World;
特点:
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
| 200 | 65 | 135 |
| 200 | 5 | 194 |
步骤定义:
var aTest = function () {
this.World = require("../support/world.js").World;
this.start = 0;
this.eat = 0;
this.Given(/^there are (d+) cucumbers$/, function(number, next) {
this.start = parseInt(number);
callback();
});
this.When(/^I eat (d+) cucumbers$/, function (number, next) {
this.eat = parseInt(number);
callback();
});
this.Then(/^I should have (d+) cucumbers$/, function (number, next) {
var left = this.start - this.eat;
if ( left != number)
callback.fail(new Error("This test didn't pass, I started with: " + this.start
+ ", ate: " + this.eat
+ " and was left with: " + left
+ ". Expected: " + number));
callback();
});
};
module.exports = aTest;
busterjs和jstestdriver都可以在自己的服务器上启动测试页面。你所要做的就是自动启动浏览器并打开测试页面。测试将在浏览器中运行,并将结果报告回服务器,在那里say可以以maven可读的格式保存。请注意,Jasmine 还有一个maven插件