Qore QUnit Module Reference  0.2
QUnit Module

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:

#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-
%new-style
%enable-all-warnings
%require-types
%strict-args
%requires ../../qlib/QUnit.qm
#%include ./_some_module_to_test
%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);
# Return for compatibility with test harness that checks return value.
set_return_value(main());
}
testMethod() {
# Test against success
testAssertion("success", \equals(), (True, True));
# Test against something else
testAssertion("failure", \equals(), (True, False), RESULT_FAILURE);
}
testSkipped() {
# Skip this test
testSkip("Because of the reason it skipped");
}
}
#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-
%new-style
%enable-all-warnings
%require-types
%strict-args
%requires ../../qlib/QUnit.qm
#%include ./_MODULE_TO_TEST_
%exec-class MyTestClass
public class MyTestClass inherits QUnit::DependencyInjectedTest {
constructor() : DependencyInjectedTest("MyTestClass", "1.0") {
addTestCase("Test something", \testMethod(), NOTHING);
# Mandatory for injected tests
setScriptPath(get_script_path());
# Return for compatibility with test harness that checks return value.
set_return_value(main());
}
nothing performModuleInjections() {
#injectIntoModule("_MODULE_TO_INJECT_INTO_(same as _MODULE_TO_TEST_?)");
}
nothing performInjections(Program p) {
#p.importClass("_class_to_inject_", "_class_to_inject_into_", True);
}
testMethod() {
# Same test style as in TestExample.qtest
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.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