27 : name (nm), category (ctg)
51 if (test->getCategory() == category)
62 if (test->getCategory().isNotEmpty())
73 jassert (newRunner !=
nullptr);
84 jassert (runner !=
nullptr);
92 jassert (runner !=
nullptr);
94 runner->beginNewTest (
this, testName);
100 jassert (runner !=
nullptr);
105 runner->addFail (failureMessage);
111 jassert (runner !=
nullptr);
113 return runner->randomForTest;
117 UnitTestRunner::UnitTestRunner() {}
122 assertOnFailure = shouldAssert;
127 logPasses = shouldDisplayPasses;
132 return results.size();
137 return results [index];
152 randomForTest =
Random (randomSeed);
155 for (
auto* t : tests)
157 if (shouldAbortTests())
160 #if JUCE_EXCEPTIONS_DISABLED 161 t->performTest (
this);
165 t->performTest (
this);
169 addFail (
"An unhandled exception was thrown!");
197 void UnitTestRunner::beginNewTest (
UnitTest*
const test,
const String& subCategory)
204 r->unitTestName = test->
getName();
205 r->subcategoryName = subCategory;
209 logMessage (
"-----------------------------------------------------------------");
210 logMessage (
"Starting test: " + r->unitTestName +
" / " + subCategory +
"...");
215 void UnitTestRunner::endTest()
217 if (
auto* r = results.getLast())
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");
236 void UnitTestRunner::addPass()
241 auto* r = results.getLast();
242 jassert (r !=
nullptr);
249 message << (r->failures + r->passes) <<
" passed";
257 void UnitTestRunner::addFail (
const String& failureMessage)
262 auto* r = results.getLast();
263 jassert (r !=
nullptr);
267 String message (
"!!! Test ");
268 message << (r->failures + r->passes) <<
" failed";
271 message <<
": " << failureMessage;
273 r->messages.add (message);
280 if (assertOnFailure) { jassertfalse; }
void runAllTests(int64 randomSeed=0)
virtual void resultsUpdated()
bool isNotEmpty() const noexcept
static Array< UnitTest * > getTestsInCategory(const String &category)
virtual void logMessage(const String &message)
void add(const ElementType &newElement)
UnitTest(const String &name, const String &category=String())
const String & getName() const noexcept
void performTest(UnitTestRunner *runner)
void logMessage(const String &message)
void runTestsInCategory(const String &category, int64 randomSeed=0)
virtual bool shouldAbortTests()
const TestResult * getResult(int index) const noexcept
void beginTest(const String &testName)
void runTests(const Array< UnitTest *> &tests, int64 randomSeed=0)
static StringArray getAllCategories()
static String toHexString(IntegerType number)
virtual void initialise()
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
static Array< UnitTest * > & getAllTests()
int getNumResults() const noexcept
bool isEmpty() const noexcept
void setAssertOnFailure(bool shouldAssert) noexcept
void expect(bool testResult, const String &failureMessage=String())
static void JUCE_CALLTYPE writeToLog(const String &message)
virtual ~UnitTestRunner()
void setPassesAreLogged(bool shouldDisplayPasses) noexcept