Qore QUnit Module Reference: QUnit Module (original) (raw)

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:

Release Notes

Version 0.4.3

Version 0.4.2

Version 0.4.1

Version 0.4

Version 0.3.3

Version 0.3.2

Version 0.3.1

Version 0.3

Version 0.2

Version 0.1