From 802d73f73f82928ea47737e3abce54b577e320cd Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 17 Jun 2020 14:52:57 +0100 Subject: [PATCH] Added startTime and endTime to UnitTest TestResult struct --- modules/juce_core/unit_tests/juce_UnitTest.cpp | 12 +++++------- modules/juce_core/unit_tests/juce_UnitTest.h | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/modules/juce_core/unit_tests/juce_UnitTest.cpp b/modules/juce_core/unit_tests/juce_UnitTest.cpp index bc1a2a65b5..c80ecd82ee 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.cpp +++ b/modules/juce_core/unit_tests/juce_UnitTest.cpp @@ -199,15 +199,11 @@ void UnitTestRunner::beginNewTest (UnitTest* const test, const String& subCatego endTest(); currentTest = test; - auto* r = new TestResult(); - results.add (r); - r->unitTestName = test->getName(); - r->subcategoryName = subCategory; - r->passes = 0; - r->failures = 0; + auto testName = test->getName(); + results.add (new TestResult (testName, subCategory)); logMessage ("-----------------------------------------------------------------"); - logMessage ("Starting test: " + r->unitTestName + " / " + subCategory + "..."); + logMessage ("Starting test: " + testName + " / " + subCategory + "..."); resultsUpdated(); } @@ -216,6 +212,8 @@ void UnitTestRunner::endTest() { if (auto* r = results.getLast()) { + r->endTime = Time::getCurrentTime(); + if (r->failures > 0) { String m ("FAILED!! "); diff --git a/modules/juce_core/unit_tests/juce_UnitTest.h b/modules/juce_core/unit_tests/juce_UnitTest.h index ca42ad1092..e843fe5391 100644 --- a/modules/juce_core/unit_tests/juce_UnitTest.h +++ b/modules/juce_core/unit_tests/juce_UnitTest.h @@ -376,18 +376,31 @@ public: */ struct TestResult { + TestResult() = default; + + explicit TestResult (const String& name, const String& subCategory) + : unitTestName (name), + subcategoryName (subCategory) + { + } + /** The main name of this test (i.e. the name of the UnitTest object being run). */ String unitTestName; /** The name of the current subcategory (i.e. the name that was set when UnitTest::beginTest() was called). */ String subcategoryName; /** The number of UnitTest::expect() calls that succeeded. */ - int passes; + int passes = 0; /** The number of UnitTest::expect() calls that failed. */ - int failures; + int failures = 0; /** A list of messages describing the failed tests. */ StringArray messages; + + /** The time at which this test was started. */ + Time startTime = Time::getCurrentTime(); + /** The time at which this test ended. */ + Time endTime; }; /** Returns the number of TestResult objects that have been performed.