Qore QUnit Module Reference  0.4.3
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.


#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-
%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.
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 -*-
%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);
# Return for compatibility with test harness that checks return value.
# mandatory for tests with dependency injections
private string getScriptPathImpl() {
return get_script_path();
private performInjectionImpl() {
# perform injections in builtin modules
injectClass("MyClass", "Class");
# custom injections for the FixedLengthUtil module
code inject = sub (Program p) {
p.importClass("Aalt", "A", True);
p.importClass("InputStreamLineIteratorFake", "Qore::InputStreamLineIterator", True);
injectUserModule("FixedLengthUtil", inject);
testMethod() {
# Same test style as in TestExample.qtest

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

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
set_return_value(auto val)
the main namespace for all public definitions in the QUnit module
Definition: QUnit.qm.dox.h:205
*string get_script_path()