Unit Testing

QUnit
// Separate tests into modules.
module("Module B");
test("some other test", function() {
        //Specify how many assertions are expected to run within a test.
        expect(2);
        //A comparison assertion, equivalent to JUnit's assertEquals.
        equals( true, false, "failing test" );
        equals( true, true, "passing test" );
});
Jasmine+Node
sudo npm install jasmine-node
node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --noColor

write a spec:

var jas = require('jasmine-node');
var player_obj = require('../src/Player.js'); // the SUT
describe("Player", function() {
    var player;
    it("should be able to play a Song", function() {
        player.play(song);
        expect(player.currentlyPlayingSong).toEqual(song);
    });
});
//...
env = jasmine.getEnv().execute();
Mocha
npm install -g mocha
mkdir test
vi test/test.js
var assert = require("assert");
describe('Array', function(){
  
describe('#indexOf()', function(){
    
it('should return -1 when the value is not present', function(){
      
assert.equal(-1, [1,2,3].indexOf(5));
      
assert.equal(-1, [1,2,3].indexOf(0));
    })
  })
});

run the test:

mocha

functional testing

Phantomjs

lanciare un test:

phantomjs test_1.js

test minimo:

    console.log('message');
    phantom.exit();

integrazione con qunit:

phantomjs /usr/local/lib/node_modules/qunit-phantomjs-runner/runner.js http://project.dev/url/to/qunit_tests.html

casperjs can be used for scraping.

Selenium + WebDriver
  • automate web browsers across many operating systems
  • non molto utilizzato, piuttosto lento e complesso da installare