UnitTest:
Filter:
UnitTesting/Classes (extension) | Testing

UnitTest
ExtensionExtension

a class for programmatic testing of classes

Description

In order to make sure a method works correctly, a test can be implemented that assures the correct behavior.

It is a common practice to write tests to clarify how an object should respond, and it may avoid inconsistencies on the long run. A test is always a subclass of UnitTest, implementing at least one method starting with test_.

NOTE: UnitTests for the Common library classes are kept in the testsuite/classlibrary directory of the SuperCollider sources.

To install, download the sources and add the directory to your sclang_conf.yaml, either by editing it or via the ScIDE preferences.

Class Methods

.gui

A graphical interface to run and browse all tests

.runTest

Run a single test for methodName.

Arguments:

methodName

Should have the format "TestPolyPlayerPool:test_prepareChildrenToBundle"

.runAll

runs all subclasses of UnitTest

.runTestClassForClass

runs testclass for a class

Arguments:

class

the class

reset

reset UnitTest environment

report

report on pass/fail

Instance Methods

.run

All method names that start with test_ are invoked.

Arguments:

reset

(describe argument here)

report

(describe argument here)

Returns:

(describe returnvalue here)

.runTestMethod

Run a single test method of this class

Arguments:

method

the method to run

Returns:

(describe returnvalue here)

Writing tests by subclassing UnitTest

Runs the test class for YourClass, which is assumed to be named TestYourClass.

If no test class if found it politely declines.

NOTE: UnitTests for the Common library classes are kept in the CommonTests quark. This enables you to easily install and uninstall these tests.

Make sure to implement the methods setUp and tearDown. They will be called before and after the test.

assert

Arguments:

test

Make sure that this returns a boolean, where true means that the test is passed.

message

posted if report is true.

onFailure

If not nil, a failure stops the tests and evaluates this function.

assertFloatEquals

Make sure that the two floats a and b equal within a given range (within).

Arguments:

a

a float

b

a float

message

posted if report is true.

onFailure

If not nil, a failure stops the tests and evaluates this function.

assertArrayFloatEquals

Make sure that the two arrays of floats a and b equal within a given range (within).

Arguments:

a

an Array of floats

b

an Array of floats

message

posted if report is true.

onFailure

If not nil, a failure stops the tests and evaluates this function.

ifAsserts

Make a further assertion only if it passed, or only if it failed.

wait

Wait for a condition, consider failed after maxTime. Only valid within a test (or a routine).

bootServer

Wait for server boot until continued. Only valid within a test (or a routine).

If already booted, then freeAll and create new allocators.

failed

call failure directly.

UnitTest (sub)class example.