27 : name (
nm), category (
ctg)
51 if (test->getCategory() == category)
62 if (test->getCategory().isNotEmpty())
94 runner->beginNewTest (
this,
testName);
113 return runner->randomForTest;
117UnitTestRunner::UnitTestRunner() {}
132 return results.size();
137 return results [index];
155 for (
auto* t :
tests)
160 #if JUCE_EXCEPTIONS_DISABLED
161 t->performTest (
this);
165 t->performTest (
this);
169 addFail (
"An unhandled exception was thrown!");
202void UnitTestRunner::beginNewTest (UnitTest*
const test,
const String&
subCategory)
210 logMessage (
"-----------------------------------------------------------------");
216void UnitTestRunner::endTest()
218 if (
auto* r = results.getLast())
224 String m (
"FAILED!! ");
225 m << r->failures << (r->failures == 1 ?
" test" :
" tests")
226 <<
" failed, out of a total of " << (r->passes + r->failures);
234 logMessage (
"Completed tests in " + getTestNameString (r->unitTestName, r->subcategoryName));
239void UnitTestRunner::addPass()
244 auto* r = results.getLast();
251 String message (
"Test ");
252 message << (r->failures + r->passes) <<
" passed";
265 auto* r = results.getLast();
270 String message (
"!!! Test ");
271 message << (r->failures + r->passes) <<
" failed";
276 r->messages.add (message);
Holds a resizable array of primitive or copy-by-value objects.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
static void JUCE_CALLTYPE writeToLog(const String &message)
Writes a string to the current logger.
A random number generator.
int nextInt() noexcept
Returns the next random 32 bit integer.
A special array for holding a list of strings.
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
Adds a string to the array as long as it's not already in there.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
Runs a set of unit tests.
void runAllTests(int64 randomSeed=0)
Runs all the UnitTest objects that currently exist.
void runTestsInCategory(const String &category, int64 randomSeed=0)
Runs all the UnitTest objects within a specified category.
virtual ~UnitTestRunner()
Destructor.
virtual bool shouldAbortTests()
This can be overridden to let the runner know that it should abort the tests as soon as possible,...
const TestResult * getResult(int index) const noexcept
Returns one of the TestResult objects that describes a test that has been run.
int getNumResults() const noexcept
Returns the number of TestResult objects that have been performed.
void setAssertOnFailure(bool shouldAssert) noexcept
Sets a flag to indicate whether an assertion should be triggered if a test fails.
void runTests(const Array< UnitTest * > &tests, int64 randomSeed=0)
Runs a set of tests.
void setPassesAreLogged(bool shouldDisplayPasses) noexcept
Sets a flag to indicate whether successful tests should be logged.
virtual void logMessage(const String &message)
Logs a message about the current test progress.
virtual void resultsUpdated()
Called when the list of results changes.
const String & getName() const noexcept
Returns the name of the test.
void logMessage(const String &message)
Writes a message to the test log.
static StringArray getAllCategories()
Returns a StringArray containing all of the categories of UnitTests that have been registered.
static Array< UnitTest * > getTestsInCategory(const String &category)
Returns the set of UnitTests in a specified category.
virtual void initialise()
You can optionally implement this method to set up your test.
UnitTest(const String &name, const String &category=String())
Creates a test with the given name and optionally places it in a category.
static Array< UnitTest * > & getAllTests()
Returns the set of all UnitTest objects that currently exist.
void beginTest(const String &testName)
Tells the system that a new subsection of tests is beginning.
void expect(bool testResult, const String &failureMessage=String())
Checks that the result of a test is true, and logs this result.
virtual void shutdown()
You can optionally implement this method to clear up after your test has been run.
virtual void runTest()=0
Implement this method in your subclass to actually run your tests.
Random getRandom() const
Returns a shared RNG that all unit tests should use.
virtual ~UnitTest()
Destructor.
void performTest(UnitTestRunner *runner)
Runs the test, using the specified UnitTestRunner.
CriticalSection::ScopedLockType ScopedLock
Automatically locks and unlocks a CriticalSection object.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
long long int64
A platform-independent 64-bit integer type.
Contains the results of a test.