Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which BDD for backbone JS applications that supports automated testing

I am building a Backbone app and I need to have automated tests. I prefer not to use selenium for automated testing.

I am looking into Jasmine and Cucumber.js. I think Jasmine might be better but in the company I work they use cucumber for the server side testing and I am investigating if cucumber.js can be used for production.

Any suggestions?

like image 807
chchrist Avatar asked Apr 04 '12 08:04

chchrist


2 Answers

Cucumber.js is quite stable and ready to be used in production. It lacks a few advanced features compared to Cucumber ruby, like scenario outlines and (now available) transforms, though. See the README for the development status table.

It can be used with Zombie.js, Phantom.js, Selenium and even within browsers. Virtually, you can use whatever assertion/testing library within your Cucumber step definitions.

As Andreas pointed out, Jasmine is aimed at unit tests/specs while Cucumber is an acceptance testing tool (hitting the whole application stack).

If you need help getting started with Cucumber.js, feel free to ping me (@jbpros on Twitter, jbpros on Freenode/#cucumber).

like image 188
jbpros Avatar answered Nov 14 '22 20:11

jbpros


I don't have enough points to add a comment to @jbpros answer, but it should be noted that Scenario Outlines are now complete in cucumber.js as stated here.

For example:

World:

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

Feature:

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 |

Steps Definition:

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;
like image 38
Naruto Sempai Avatar answered Nov 14 '22 20:11

Naruto Sempai