buttonmen-dev/buttonmen — pull request #301 by cgolubi1 (2013-12-21 03:49:30+00:00)
Title: add Qunit and unit tests of responder.php

This pull request adds unit/regression tests at several new places in the UI-to-backend chain:
* At the front end, install the QUnit JS unit test framework and make it available at /test-ui/. This UI is user-visible (i.e. anyone can run these tests from their browser), and makes all of its queries to dummy_responder.php rather than responder.php.
* Next, add dummy_responder.php, a responder.php workalike which never talks to a database, but instead always returns static canned responses to queries. Should be safe for a user-visible unit test to bang on, or ideally for people who are writing custom code against the buttonmen API to do some initial testing again.
* Next, add a PHP unit test file, responderTest.php, which tests the syntax of the responses returned by responder.php, by comparing the format of those responses to canned results from dummy_responder.php. This is regression testing so that if the syntax of the public API changes by accident, we are more likely to catch it. This required a slight refactor of responder.php, so that it can be invoked either directly via POST request, or via PHP require.
* Also, add an audit script to make sure that every JavaScript function has a unit test (important because JS is so hairy to work with), and a wrapper script, /usr/local/bin/run_buttonmen_tests, which can be run from the vagrant CLI to do all CLI audits and tests (i.e. all working audits and tests except for QUnit)
* Fixes #232

Known limitations:
* /test-ui/ isn't installed on pagoda, so we can't yet run QUnit on pagoda
* The login and logout functions are not stubbed/tested in any of QUnit, dummy_responder, or responderTest
* In addition to Login, the Newgame and Newuser tests are unimplemented in QUnit
* The submitTurn test is unimplemented in responderTest
* A number of the new tests are kind of perfunctory --- my goal was to get the basic framework in place, so that from here on it will be feasible to implement test-first-bug-fixing in these various areas. As written, the tests do not do very much new innovative bug fixing (though it will be interesting to see what happens when people run QUnit using other browsers/OSes).