TestCase - Documentation

Index

Terms of usage

One of the general idea of the project is to provide a test environment which the developers could start use right away and follow all their old habits. So we provide a simple API which offers underscored and camelised functions which works the same way and in general have well known by another unit-testing systems semantics.

Another main idea of the project is to provide a gui which will not break your existing page layout, design, styles etc. So you could run the test right in your pages environment if you like so. For this reason we have got this popup test-report system. Therefore you can safely include your unit-tests right into your page scripts and run them whenever you like.

In additional, since the version 1.0, the reporting system provides some features which allows you to skip/activate the cases right on the report popup, and special select-box which allows you to filter your cases and display/run only the ones you need.

NOTE: if you see those goods disabled, that means you have cookies disabled on your browser. We use cookies to keep the changes active between the page reloads. So you should enable cookies if wish to use the features.

Writing tests

The library peresents two public classes TestCase and TestSuite. The first one is the testing base by itself and the second one is a collector for your tests.

General Test Example

var MyTest = TestCase.create({ name: "MyTest", // <- this is an optional test identifier, to see it in the test-results testFoo: function() { this.assertTrue(true); }, testBla: function() { this.assertFalse(false); } });

And there's another class-method which allows you to extend existing test-cases. .extend() NOTE: the method will overwrite methods of your test-case which are already exists.

TestCase extending.

var Test = TestCase.create(); Test.extend({ testSomething: function() {} });

Once you've got a test-class, you can run it in several ways. First, each test has the method run(), which can be called as a static method or as an instance method. // like that MyTest.run(); // or like that var test = new MyTest; test.run();

Since the version 2.0, there's another test-starting methods runOnLoad() (run_on_load()) which will wire your test to be started when the page is loaded.

Run On Load

var Test = TestCase.create({...}); Test.runOnLoad(); // or as instance var test = new Test(); test.runOnLoad();

The second public class TestSuite is just a container for the test-cases. You can put in a test-suite any number of tests you like and when you run the suite it will automatically instance and run all the tests which belongs to it.

TestSuite example

var test_suite = new TestSuite(Test1, Test2, Test3...); // or var test_suite = new TestSuite(); test_suite.add(Test1); test_suite.add(Test2, Test3, ...); // you can remove tests out of the list test_suite.remove(Test2); // to run all the suite test, use the run() method test_suite.run(); // or run on load test_suite.runOnLoad();