|
| | UnitTest (const String &name, const String &category=String()) |
| virtual | ~UnitTest () |
| const String & | getName () const noexcept |
| const String & | getCategory () const noexcept |
| void | performTest (UnitTestRunner *runner) |
| virtual void | initialise () |
| virtual void | shutdown () |
| virtual void | runTest ()=0 |
| void | beginTest (const String &testName) |
| void | expect (bool testResult, const String &failureMessage=String()) |
| template<class ValueType> |
| void | expectEquals (ValueType actual, ValueType expected, String failureMessage=String()) |
| template<class ValueType> |
| void | expectNotEquals (ValueType value, ValueType valueToCompareTo, String failureMessage=String()) |
| template<class ValueType> |
| void | expectGreaterThan (ValueType value, ValueType valueToCompareTo, String failureMessage=String()) |
| template<class ValueType> |
| void | expectLessThan (ValueType value, ValueType valueToCompareTo, String failureMessage=String()) |
| template<class ValueType> |
| void | expectGreaterOrEqual (ValueType value, ValueType valueToCompareTo, String failureMessage=String()) |
| template<class ValueType> |
| void | expectLessOrEqual (ValueType value, ValueType valueToCompareTo, String failureMessage=String()) |
| template<class ValueType> |
| void | expectWithinAbsoluteError (ValueType actual, ValueType expected, ValueType maxAbsoluteError, String failureMessage=String()) |
| void | logMessage (const String &message) |
| Random | getRandom () const |
This is a base class for classes that perform a unit test.
To write a test using this class, your code should look something like this:
{
public:
MyTest() :
UnitTest (
"Foobar testing") {}
void runTest() override
{
beginTest ("Part 1");
expect (myFoobar.doesSomething());
expect (myFoobar.doesSomethingElse());
beginTest ("Part 2");
expect (myOtherFoobar.doesSomething());
expect (myOtherFoobar.doesSomethingElse());
...etc..
}
};
UnitTest(const String &name, const String &category=String())
Definition juce_UnitTest.cpp:26
static int test(SerdEnv *env, bool top_level, bool pretty_numbers)
Definition sratom_test.c:79
To run a test, use the UnitTestRunner class.
- See also
- UnitTestRunner
@tags{Core}
Checks that the result of a test is true, and logs this result.
In your runTest() method, you should call this method for each condition that you want to check, e.g.
{
expect (getThing() == someThing);
...etc...
}
void beginTest(const String &testName)
Definition juce_UnitTest.cpp:89
void expect(bool testResult, const String &failureMessage=String())
Definition juce_UnitTest.cpp:97
int y
Definition inflate.c:1588
unsigned x[BMAX+1]
Definition inflate.c:1586
If testResult is true, a pass is logged; if it's false, a failure is logged. If the failure message is specified, it will be written to the log if the test fails.
| Random juce::UnitTest::getRandom |
( |
| ) |
const |
Returns a shared RNG that all unit tests should use. If a test needs random numbers, it's important that when an error is found, the exact circumstances can be re-created in order to re-test the problem, by repeating the test with the same random seed value. To make this possible, the UnitTestRunner class creates a master seed value for the run, writes this number to the log, and then this method returns a Random object based on that seed. All tests should only use this method to create any Random objects that they need.
Note that this method will return an identical object each time it's called for a given run, so if you need several different Random objects, the best way to do that is to call Random::combineSeed() on the result to permute it with a constant value.