The base class for any Aria Templates test is
On top of basic assertions it allows to assert logs and events, it provides mocking and sandboxing.
Here is an example of unit test class.
A Test Case (cf. API doc) will usually feature several single test methods. All tests are supposed to be completely independent from each other, and the order in which they are executed should not be taken into consideration.
When running a TestCase, all the methods defined in the prototype and with a name starting with test will be considered as test methods. It is mandatory to follow this naming convention.
aria.jsunit.TestCase extends the class
aria.jsunit.Assert, which provides the following assertions:
assertFalse: Test if a value is true or false
assertNotEquals: Test that two values are strictly equal
assertJsonNotEquals: Test for deep equality of objects / array
assertJsonContains: Assert that an object is included in a bigger container.
assertLogsEmpty: Test that no class logged an error message.
assertErrorInLogs: Test that a precise error has been logged.
Error messages for which a corresponding assertion is not performed will make the test fail
failExplicitly let the test fail with a given message.
assert* methods accept as message parameter used to better understand why the assert failed.
It is usually the first parameter after the value(s) being asserted,
for more information refer to the API documentation.
Asynchronous tests are a special kind of test methods, and their name should start with
The easiest way to do an asynchronous test is to directly call the asynchronous method, passing a callback defined in the Test Case. This callback will then be responsible of notifying the tester when the test is finished.
The callback can be defined in the prototype of the Test Case, but in this case, make sure its name doesn't start with test,
otherwise it will be picked up and executed on its own as a
To notify the test runner,
aria.jsunit.TestCase provides the
If several tests in a single test case are using the same kind of objects in their tests,
it can be interesting to define the
tearDown methods in the
$prototype of the
These two methods are called before and after each test method.
In some cases we want to assert that an event has been raised or not by a given class. This is a basic form of spy.
aria.jsunit.TestCase provides the following methods
unregisterObjectListen to all events fired by a given object.
assertEventNotFiredAssert that en event with a given name has been raised.
getEventGet the event object of a given event name, useful to assert that parameters are passed correctly.
The following is an example test case using