void UnitTestRunner::addFail (const String& failureMessage) { { const ScopedLock sl (results.getLock()); TestResult* const r = results.getLast(); jassert (r != nullptr); // You need to call UnitTest::beginTest() before performing any tests! r->failures++; String message ("!!! Test "); message << (r->failures + r->passes) << " failed"; if (failureMessage.isNotEmpty()) message << ": " << failureMessage; r->messages.add (message); logMessage (message); } resultsUpdated(); if (assertOnFailure) { jassertfalse; } }
void UnitTestRunner::runTests (const Array<UnitTest*>& tests, int64 randomSeed) { results.clear(); resultsUpdated(); if (randomSeed == 0) randomSeed = Random().nextInt (0x7ffffff); randomForTest = Random (randomSeed); logMessage ("Random seed: 0x" + String::toHexString (randomSeed)); for (int i = 0; i < tests.size(); ++i) { if (shouldAbortTests()) break; #if JUCE_EXCEPTIONS_DISABLED tests.getUnchecked(i)->performTest (this); #else try { tests.getUnchecked(i)->performTest (this); } catch (...) { addFail ("An unhandled exception was thrown!"); } #endif } endTest(); }
void UnitTestRunner::beginNewTest (UnitTest* const test, const String& subCategory) { endTest(); currentTest = test; TestResult* const r = new TestResult(); results.add (r); r->unitTestName = test->getName(); r->subcategoryName = subCategory; r->passes = 0; r->failures = 0; logMessage ("-----------------------------------------------------------------"); logMessage ("Starting test: " + r->unitTestName + " / " + subCategory + "..."); resultsUpdated(); }
void UnitTestRunner::addPass() { { const ScopedLock sl (results.getLock()); TestResult* const r = results.getLast(); jassert (r != 0); // You need to call UnitTest::beginTest() before performing any tests! r->passes++; String message ("Test "); message << (r->failures + r->passes) << " passed"; logMessage (message); } resultsUpdated(); }
void UnitTestRunner::runTests (const Array<UnitTest*>& tests, const bool assertOnFailure_) { results.clear(); assertOnFailure = assertOnFailure_; resultsUpdated(); for (int i = 0; i < tests.size(); ++i) { try { tests.getUnchecked(i)->performTest (this); } catch (...) { addFail ("An unhandled exception was thrown!"); } } endTest(); }
void UnitTestRunner::runTests (const Array<UnitTest*>& tests) { results.clear(); resultsUpdated(); for (int i = 0; i < tests.size(); ++i) { if (shouldAbortTests()) break; try { tests.getUnchecked(i)->performTest (this); } catch (...) { addFail ("An unhandled exception was thrown!"); } } endTest(); }