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);
}
testMethod() {
testAssertion("success", \equals(), (True, True));
testAssertion("failure", \equals(), (True, False), RESULT_FAILURE);
}
testSkipped() {
testSkip("Because of the reason it skipped");
}
}
%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);
}
nothing performModuleInjections() {
}
nothing performInjections(Program p) {
}
testMethod() {
testAssertion("success", \equals(), (True, 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.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