2012-04-04 12 views
6

Sto costruendo un'applicazione Backbone e ho bisogno di avere test automatizzati automatizzati. Preferisco non usare il selenio per i test automatici.Quale BDD per applicazioni backbone JS che supporta testing

Sto cercando di Jasmine e Cucumber.js. Credo che Jasmine potrebbe essere migliore, ma alla società per cui lavoro che usano il cetriolo per la sperimentazione lato server e sto studiando se cucumber.js possono essere utilizzati per la produzione.

Qualche suggerimento?

+0

Cosa si intende per test automatizzati. Chiedo perché lei menziona Selenium, che è per test di integrazione e Jasmine che è per test unitari. –

+0

Ciò che intendo è che voglio che i miei test vengano eseguiti automaticamente senza dover testare manualmente ciascuna funzionalità nel browser. Pensavo che Jasmine fosse uno strumento BDD. – chchrist

risposta

10

Cucumber.js è abbastanza stabile e pronto per essere utilizzato in produzione. Manca un paio di caratteristiche avanzate rispetto al cetriolo rubino, come scenario delinea e (ora disponibile) si trasforma, però. Vedere lo README per la tabella dello stato di sviluppo.

Può essere utilizzato con Zombie.js, Phantom.js, Selenio e anche all'interno dei browser. Virtualmente, puoi usare qualsiasi libreria di asserzione/test all'interno delle definizioni dei passi di Cucumber.

Come Andreas sottolineato, gelsomino si rivolge a unit test/spec mentre cetriolo è uno strumento di test di accettazione (colpire l'intero stack applicativo).

Se hai bisogno di aiuto per iniziare con Cucumber.js, sentiti libero di inviarmi un ping (@jbpros su Twitter, jbpros su Freenode/# cetriolo).

0

Entrambi, busterjs e jstestdriver, possono avviare il proprio server che ospita la pagina di test. Tutto quello che devi fare è avviare i tuoi browser automaticamente e aprire la pagina di test. Il test verrà eseguito nel browser e riporterà il risultato sul server, dove si dice che può essere salvato in un formato leggibile. Nota c'è anche un plugin Maven per Jasmine

+1

Vale anche la pena ricordare che il gelsomino può anche funzionare senza testa con i phantomjs – ggozad

1

Non ho abbastanza punti per aggiungere un commento alla risposta @jbpros, ma è necessario notare che Scenario Outlines sono ora completi in cucumber.js come indicato here.

Ad esempio:

mondo:

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

Caratteristica:

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 | 

Passi Definizione:

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;