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_
.
When running all tests of one class (see run), each test method is called in a separate instance of this class. Test methods, therefore, do not interfere with each other.
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.
A graphical interface to run and browse all tests
Accessor controlling whether passing tests should be reported. Defaults to true
. See also *passVerbosity which controls how much detail is reported from passing tests when this is set to true.
(value) |
Should be |
Accessor controlling whether extra details should be reported for passing tests.
Defaults to UnitTest.full
so that all details are reported; however this behaviour may be too verbose for some, for whom it is sufficient to see that a test is passing without needing to see the detail. If set to UnitTest.brief
, and *reportPassesis true, passes will be reported, but without any extra details which may be provided by assertions.
(value) |
Should be |
Run all methods whose names begin with test_
.
reset |
If |
report |
If |
Run a single test method.
methodName |
A String referring to the class and test method within it, e.g. |
Run the entire test suite. As this method addresses the entire test suite, it should be called only on UnitTest
. Calling it on any of its subclasses will result in throwing an Error
.
Run a single test method of this class
method |
the method to run |
report |
Reports the result of the test if |
(describe returnvalue here)
Asserts that an expression must be true.
boolean |
A boolean, where |
message |
A message describing the purpose of the assertion, e.g. |
report |
Reports the result of the test if |
onFailure |
If not |
details |
Some optional extra details which will be passed to the reporting framework for display unless brief reporting is requested (see *passVerbosity). |
Asserts that an expression a
is equal to the value b
, where equality is determined according to a
's implementation of ==
.
Automatically passes details of the equality check to the reporting framework, which will be displayed if the assertion fails, and also if it passes and *reportPasses is true
and *passVerbosity is not set to UnitTest.brief
.
a |
the experimentally produced value |
b |
the expected value |
message |
A message describing the purpose of the assertion, e.g. |
report |
Reports the result of the test if |
onFailure |
If not |
Asserts that an expression a
returning a float is within a given range (within
) of being equal to b
.
Automatically passes details of the equality check to the reporting framework, which will be displayed if the assertion fails, and also if it passes and *reportPasses is true
and *passVerbosity is not set to UnitTest.brief
.
a |
the experimentally produced float value |
b |
the expected float value |
message |
A message describing the purpose of the assertion, e.g. |
within |
The range within which |
report |
Reports the result of the test if |
onFailure |
If not |
Make sure that the two arrays of floats a
and b
equal within a given range (within
).
a |
the experimentally produced value, which is an |
b |
the |
message |
A message describing the purpose of the assertion, e.g. |
within |
The range within which each item of |
report |
Reports the result of the test if |
onFailure |
If not |
Make a further assertion only if it passed, or only if it failed.
Make sure that a specific Exception or Error is thrown.
func |
Pass the code that is expected to throw an error in this function. |
errorClass |
The class or class name which the error should be kind of. |
message |
A message describing the purpose of the assertion. |
report |
Reports the result of the test if |
onFailure |
If not |
details |
Some optional extra details which will be passed to the reporting framework for display unless brief reporting is requested (see *passVerbosity). |
Make sure that a specific Exception or Error is not thrown. For arguments, see -assertException.
Wait for a predicate function to return true
. Considers the test failed after maxTime
. Only valid within a test (or a routine).
Wait for server boot until continued. Only valid within a test (or a routine).
If already booted, then freeAll and create new allocators.
Supply some debugging information relevant to the currently running test case. This will be displayed immediately preceding any details which may be displayed through use of the details
argument of -passed and -failed.
text |
The debugging text. |
will result in:
Register a passed test.
method |
Name of the method in which the test is passing. |
message |
A message describing the purpose of the assertion, e.g. |
report |
Reports the result of the test if true and *reportPasses is true. |
details |
Some optional extra details which will be displayed if *reportPasses is true and *passVerbosity is not set to |
Register a test failure.
method |
Name of the method in which the test is failing. |
message |
A message describing the purpose of the assertion, e.g. |
report |
Reports the result of the test if true. |
details |
Some optional extra details which will be displayed if |
Write tests by subclassing UnitTest, and defining methods whose names begins test_
. Each test method will be called from a fresh instance of the subclass.
If you implement the methods setUp
and tearDown
in your test class, they will be called before and after every test. This can help to eliminate repetitive code, and makes it easier to maintain your tests by ensuring that they all run under the same set of conditions.