-
Notifications
You must be signed in to change notification settings - Fork 24
Unit Testing Framework
SculeJS uses the Mocha test drive development framework.
Mocha allows you to run tests in NodeJS - for browser based or Titanium applications I've developed a custom TDD framework called JSUnit. The first thing you should do once you've cloned the SculeJS repository is run the test suite to ensure that everything is functioning as expected. You don't need to install any dependencies (other than node) in order to do this:
$ cd sculejs
$ mocha tests/*
Tests from trunk should ALWAYS pass. If you see a failure then run the tests again - if the test consistently fails then something is afoot and you should probably make sure your environment is set up correctly, then log a ticket if things are still broken.
Writing tests with expresso is a piece of cake, for a quick start guide just check out the test suite for SculeJS in Github.
An example of a simple JSUnit test suite using all currently supported assertions is provided below:
var jsunit = require('../lib/com.scule.jsunit');
function testDemo() {
var o = {foo:true};
jsunit.assertTrue(true);
jsunit.assertFalse(false);
jsunit.assertEquals('foo', 'foo');
jsunit.assertNotEquals('foo', 'bar');
jsunit.assertLessThan(1, 2);
jsunit.assertLessThanEqualTo(1, 2);
jsunit.assertGreaterThan(2, 1);
jsunit.assertGreaterThanEqualTo(2, 1);
jsunit.assertExists('foo', o);
jsunit.assertNotExists('bar', o);
};
(function() {
jsunit.resetTests(__filename);
jsunit.addTest(testDemo);
jsunit.runTests();
}());
If you're planning on contributing please ensure your code is thoroughly tested, also make sure that supporting test cases are included in your pull request.