27 : name (
nm), category (
ctg)
51 if (
test->getCategory() == category)
62 if (
test->getCategory().isNotEmpty())
84 jassert (runner !=
nullptr);
92 jassert (runner !=
nullptr);
94 runner->beginNewTest (
this,
testName);
100 jassert (runner !=
nullptr);
111 jassert (runner !=
nullptr);
113 return runner->randomForTest;
117UnitTestRunner::UnitTestRunner() {}
132 return results.
size();
137 return results [index];
160 #if JUCE_EXCEPTIONS_DISABLED
161 t->performTest (
this);
165 t->performTest (
this);
169 addFail (
"An unhandled exception was thrown!");
202 auto* r =
new TestResult();
204 r->unitTestName =
test->getName();
209 logMessage (
"-----------------------------------------------------------------");
215void UnitTestRunner::endTest()
217 if (
auto* r = results.
getLast())
221 String m (
"FAILED!! ");
222 m << r->failures << (r->failures == 1 ?
" test" :
" tests")
223 <<
" failed, out of a total of " << (r->passes + r->failures);
231 logMessage (
"All tests completed successfully");
236void UnitTestRunner::addPass()
239 const ScopedLock sl (results.
getLock());
242 jassert (r !=
nullptr);
248 String message (
"Test ");
249 message << (r->failures + r->passes) <<
" passed";
257void UnitTestRunner::addFail (
const String& failureMessage)
260 const ScopedLock sl (results.
getLock());
263 jassert (r !=
nullptr);
267 String message (
"!!! Test ");
268 message << (r->failures + r->passes) <<
" failed";
270 if (failureMessage.isNotEmpty())
271 message <<
": " << failureMessage;
273 r->messages.add (message);
280 if (assertOnFailure) { jassertfalse; }
const TypeOfCriticalSectionToUse & getLock() const noexcept
int size() const noexcept
void removeFirstMatchingValue(ParameterType valueToRemove)
void add(const ElementType &newElement)
bool addIfNotAlreadyThere(ParameterType newElement)
ElementType getLast() const noexcept
static void JUCE_CALLTYPE writeToLog(const String &message)
bool isEmpty() const noexcept
static String toHexString(IntegerType number)
void runAllTests(int64 randomSeed=0)
void runTestsInCategory(const String &category, int64 randomSeed=0)
virtual ~UnitTestRunner()
virtual bool shouldAbortTests()
const TestResult * getResult(int index) const noexcept
int getNumResults() const noexcept
void setAssertOnFailure(bool shouldAssert) noexcept
void runTests(const Array< UnitTest * > &tests, int64 randomSeed=0)
void setPassesAreLogged(bool shouldDisplayPasses) noexcept
virtual void logMessage(const String &message)
virtual void resultsUpdated()
void logMessage(const String &message)
static StringArray getAllCategories()
static Array< UnitTest * > getTestsInCategory(const String &category)
virtual void initialise()
UnitTest(const String &name, const String &category=String())
static Array< UnitTest * > & getAllTests()
void beginTest(const String &testName)
void expect(bool testResult, const String &failureMessage=String())
void performTest(UnitTestRunner *runner)