Writing Tests for the QuIP Stack - SBU-BMI/quip_distro GitHub Wiki

This guide is to document the testing process for camicroscope. This document covers functional tests using CasperJS. The tests mimic user behavior like clicking buttons, panning, zooming, etc.

Setting up the testing environment

  • Install Node.js
  • Install PhantomJS
  • Install CasperJS npm install -g casperjs

Write tests in the /tests directory.

Run casperjs test tests/ to run your tests locally.

Writing casper tests

CasperJS's documentation is available here. It shows how you can use different selectors and trigger user behaviour.

Sample test

The sample select.php.js file shows a simple test for the select.php page in the QuIP stack.

var url = "http://localhost/select.php"; //open select.php, change this to http://testserver/select.php while testing against a test server.


casper.test.begin('Link to flextables works fine', 3, function suite(test) {
    casper.start(url, function() {
        test.assertExists('a[href="/FlexTables/index.php"]', "link to camicroscope is found"); //check whether link to flex tables is found
        this.click('a[href="/FlexTables/index.php"]'); //click flex tables link
    });
    
    /*
    casper.then(function() {
        test.assertExists("#whoosh", "flex tables looks okay"); //check if it's able to open flex tables.
    });
    */

    casper.run(function() {
        test.done();
    });
});

In this simple test, we check whether a link to FlexTables exists or not: test.assertExists('a[href="FlexTables/index.php"]')

Check the CasperJS documentation to write more advanced tests; the goal would be to mimic the end user's behavior programmatically using casper.

These tests will be integrated and run on Travis CI.