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

Notice: Undefined variable: browserName in /var/www/taziomirandola.it/lib/Visitors.php on line 86

Notice: Undefined variable: browserName in /var/www/taziomirandola.it/lib/Visitors.php on line 96

Deprecated: strripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /var/www/taziomirandola.it/lib/Visitors.php on line 96

Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in /var/www/taziomirandola.it/lib/Visitors.php on line 39

Fatal error: Uncaught TypeError: Argument 1 passed to safe_text() must be of the type string, null given, called in /var/www/taziomirandola.it/lib/Visitors.php on line 39 and defined in /var/www/taziomirandola.it/lib/Visitors.php:162 Stack trace: #0 /var/www/taziomirandola.it/lib/Visitors.php(39): safe_text() #1 /var/www/taziomirandola.it/lib/Visitors.php(124): Visitors::getData() #2 [internal function]: Visitors::log() #3 {main} thrown in /var/www/taziomirandola.it/lib/Visitors.php on line 162