【问题标题】:Which BDD for backbone JS applications that supports automated testing支持自动化测试的主干 JS 应用程序的 BDD
【发布时间】:2023-04-10 14:59:01
【问题描述】:

我正在构建一个 Backbone 应用程序,我需要进行自动化测试。我不喜欢使用 selenium 进行自动化测试。

我正在研究 Jasmine 和 Cucumber.js。我认为 Jasmine 可能会更好,但在我工作的公司中,他们使用 cucumber 进行服务器端测试,我正在调查 cucumber.js 是否可以用于生产。

有什么建议吗?

【问题讨论】:

  • 自动化测试是什么意思。我问你是因为你提到了用于集成测试的 Selenium 和用于单元测试的 Jasmine。
  • 我的意思是我希望我的测试能够自动运行,而不必手动测试浏览器中的每个功能。我以为 Jasmine 是一个 BDD 工具。

标签: javascript cucumber automated-tests bdd jasmine


【解决方案1】:

Cucumber.js 非常稳定,可以在生产环境中使用。与 Cucumber ruby​​ 相比,它缺少一些高级功能,例如 scenario outlines 和(现在可用)转换。开发状态表见README

它可以与 Zombie.js、Phantom.js、Selenium 甚至在浏览器中一起使用。实际上,您可以在 Cucumber 步骤定义中使用任何断言/测试库。

正如 Andreas 所指出的,Jasmine 的目标是单元测试/规范,而 Cucumber 是一种验收测试工具(针对整个应用程序堆栈)。

如果您需要 Cucumber.js 入门方面的帮助,请随时联系我(Twitter 上的@jbpros,Freenode/#cucumber 上的 jbpros)。

【讨论】:

    【解决方案2】:

    我没有足够的分数来为@jbpros 答案添加评论,但应该注意Scenario Outlines 现在在 cucumber.js 中已完成,如here 所述。

    例如:

    世界:

    // 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;
    

    【讨论】:

      【解决方案3】:

      busterjsjstestdriver 都可以在自己的服务器上启动测试页。您所要做的就是自动启动浏览器并打开测试页面。测试将在浏览器中运行并将结果报告回服务器,可以将其保存为 maven 可读格式。注意Jasmine还有一个maven插件

      【讨论】:

      • 另外值得一提的是,jasmine 也可以用 phantomjs 无头运行
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多