What is a BDD for basic JS applications that support automatic testing

I am creating a Backbone application and I need to have automated tests. I prefer not to use selenium for automatic testing.

I study Jasmine and Cucumber.js. I think Jasmine might be better, but in the company I work for, they use cucumber for server-side testing, and I am studying whether cucumber.js can be used for production.

Any suggestions?

+6
source share
3 answers

Cucumber.js is quite stable and ready for use in production. It does not have several advanced features compared to the Cucumber ruby, for example, the script outline and (now available). See README for a development status table.

It can be used with Zombie.js, Phantom.js, selenium and even inside browsers. In fact, you can use any approval / testing library in the Cucumber step definitions.

As Andreas noted, Jasmine is aimed at unit tests / specifications, while Cucumber is an acceptance testing tool (hit the entire application stack).

If you need help starting up with Cucumber.js, feel free to ping me (@jbpros on Twitter, jbpros on Freenode / # oucumber).

+10
source

I donโ€™t have enough points to add a comment to @jbpros answer, but it should be noted that the Scripting scripts have now completed cucumber.js, as indicated here .

For instance:

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; 

Characteristic:

 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 | 

Step 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; 
+1
source

Both, busterjs and jstestdriver , can start there their own server, which hosts the test version. All you have to do is automatically launch the browser and open the test page. The test will be launched in the browser and will report the results to the server, where you can save it in maven format. Please note that there is also a maven plugin for Jasmine

0
source

Source: https://habr.com/ru/post/912367/


All Articles