Introduction to the QUnit Module
The QUnit module provides a framework for automated testing.
It contains base classes for creating test cases and test suites. It also provides a dependency injection helper for mocking pre-existing classes without modifying their code.
It also provides a number of pre-defined testing functions for use in assertions.
Examples:
%new-style
%enable-all-warnings
%require-types
%strict-args
%requires ../../qlib/QUnit.qm
%exec-class QUnitTest
public
class QUnitTest inherits
QUnit::Test {
constructor() : Test("QUnitTest", "1.0") {
addTestCase("What this method is testing", \testMethod(), NOTHING);
addTestCase("Skipped test", \testSkipped(), NOTHING);
set_return_value(main());
}
testMethod() {
testAssertion("success", \equals(), (True, True));
testAssertion("failure", \equals(), (True, False), RESULT_FAILURE);
}
testSkipped() {
testSkip("Because of the reason it skipped");
}
}
the main namespace for all public definitions in the QUnit module
Definition QUnit.qm.dox.h:205
%new-style
%enable-all-warnings
%require-types
%strict-args
%requires ../../qlib/QUnit.qm
%exec-class MyTestClass
public
class MyTestClass inherits
QUnit::DependencyInjectedTest {
constructor() : DependencyInjectedTest("MyTestClass", "1.0") {
addTestCase("Test something", \testMethod(), NOTHING);
set_return_value(main());
}
private string getScriptPathImpl() {
return get_script_path();
}
private performInjectionImpl() {
injectClass("MyClass", "Class");
child.loadModule("reflection");
code inject = sub (Program p) {
p.importClass("Aalt", "A", True);
p.importClass("InputStreamLineIteratorFake", "Qore::InputStreamLineIterator", True);
};
injectUserModule("FixedLengthUtil", inject);
}
testMethod() {
assertTrue(True);
}
}
Running tests
Tests are ran by simply executing the test script:
qore test.qtest [OPTIONS]
A number of options is available, controlling the behaviour/output of the test
Supported output formats of test reports
Currently the module provides the following output formats:
- plainquiet - human readable quiet format, prints only failures and a short summary at the end, which is also the default
- plaintext - human readable format, prints one statement per test
- junit - machine readable format for further processing
Release Notes
Version 0.4.3
- added constructors for use with languages that don't support lvalue references (ex: Python) (issue 3934)
Version 0.4.2
- allow QUnit to be used from other languages like Java (issue 3857)
Version 0.4.1
- allow binary modules to be subjected to dependency injections (issue 3382)
- allow tests to be nested (issue 3306)
Version 0.4
Version 0.3.3
- improved output in assertion failures for strings with special whitespace and for multi-line data structures (issue 2680)
Version 0.3.2
- improved error location reporting by providing all stack location information up until the QUnit call to cover the case when multiple code layers are used such as one or more test modules (issue 1720)
- overloaded testAssertionValue supports auto/number/float
- more verbose output when number/float difference is found
Version 0.3.1
- added the following methods:
Version 0.3
- updated for complex types
Version 0.2
- fixed showing the assertion location when there are test modules on top of QUnit.qm (issue 1046)
Version 0.1
- initial version of module