The qooxdoo Test Runner
“Test Runner” is a unit testing framework that fully supports testing qooxdoo classes. It is similar to but does not require JSUnit or any other JavaScript unit testing framework. If you look at the component section of a qooxdoo distribution under component/testrunner/, you will find the Test Runner sources, together with a mockup test class. In the framework/ section you can create a Test Runner instance with all test classes from the qooxdoo framework by running:
./generate.py test
Test Runner provides a convenient interface to test classes that have been written to that end. You can run single tests, or run a whole suite of them at once.
The Test Runner framework can also be deployed for your own application. It provides a GUI, a layer of infrastructure and a certain interface for arbitrary test classes. So now you can write your own test classes and take advantage of the Test Runner environment.
How to deploy Test Runner for your own development
This section assumes that your qooxdoo application bears on the structure of the qooxdoo skeleton application. Then this is what you have to do:
Writing Test Classes
- You have to code test classes that perform the indiviudal tests. These test classes have to comply to the following constraints:
- They have to be within the name space of your application.
- They have to be derived from
qx.dev.unit.TestCase. - They have to define member functions with names starting with
test*. These methods will be available as individual tests. - Apart from that you are free to add other member functions, properties etc., and to instantiate other classes to your own content. But you will usually want to instantiate classes of your current application and invoke their methods in the test functions.
- In order to communicate the test results back to the Test Runner framework exceptions are used. No exception means the test went fine, throwing an exception from the test method signals a failure. Return values from the test methods are not evaluated.
- To model your test method behaviour, you can use the methods inherited from
qx.dev.unit.TestCasewhich encapsulate exceptions in the form of assertions:assert,assertFalse,assertEquals,assertNumber, ... - These functions take values which are compared (either among each other or to some predefined value) and a message string, and raise an exception if the comparison fails.- A similar list of methods of the form
assert*DebugOnis available, which are only evaluated if the debug variantqx.debugis on (see Variants). - See the documentation for the
qx.dev.unit.TestCaseclass for more information on the available assertions.
Create the Test Application
- Run
generate.py testfrom the top-level directory of your application. This will generate the appropriate test application for you, which will be available in the subfoldertestastest/index.html. Open this file in your browser and run your tests. - Equally, you can invoke
generate.py test-source. This will generate the test application, but allows you to use the source version of your application to run the tests on. In doing so the test application links directly into the source tree of your application. This allows for test-driven development where you simultaneously develop your source classes, the test classes and run the tests. All you need to do is to change the URL of the “test backend application” (the textfield in the upper middle of the TestRunner frame) fromtests.html(which is the default) totests-source.html. (Caveat: Ifgenerate.py test-sourceis the first thing you do, you might get an error when TestRunner starts, since the default tests.html has not been built; just change the URL and continue). For example, the resulting URL will look something like this:html/tests-source.html?testclass=<your_app_name>
After that, you just reload the backend application by hitting the reload button to the right to see and test your changes in the TestRunner.
