1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

UnitTest: Add a way to get and run tests by name

This commit is contained in:
Anthony Nicholls 2025-06-27 15:08:54 +01:00 committed by Anthony Nicholls
parent 51b46f3cd1
commit 59612477bb
2 changed files with 30 additions and 0 deletions

View file

@ -66,6 +66,20 @@ Array<UnitTest*> UnitTest::getTestsInCategory (const String& category)
return unitTests;
}
Array<UnitTest*> UnitTest::getTestsWithName (const String& name)
{
if (name.isEmpty())
return getAllTests();
Array<UnitTest*> unitTests;
for (auto* test : getAllTests())
if (test->getName() == name)
unitTests.add (test);
return unitTests;
}
StringArray UnitTest::getAllCategories()
{
StringArray categories;
@ -196,6 +210,11 @@ void UnitTestRunner::runTestsInCategory (const String& category, int64 randomSee
runTests (UnitTest::getTestsInCategory (category), randomSeed);
}
void UnitTestRunner::runTestsWithName (const String& name, int64 randomSeed)
{
runTests (UnitTest::getTestsWithName (name), randomSeed);
}
void UnitTestRunner::logMessage (const String& message)
{
Logger::writeToLog (message);

View file

@ -106,6 +106,9 @@ public:
/** Returns the set of UnitTests in a specified category. */
static Array<UnitTest*> getTestsInCategory (const String& category);
/** Returns the set of UnitTests with a specified name. */
static Array<UnitTest*> getTestsWithName (const String& name);
/** Returns a StringArray containing all of the categories of UnitTests that have been registered. */
static StringArray getAllCategories();
@ -369,6 +372,14 @@ public:
*/
void runTestsInCategory (const String& category, int64 randomSeed = 0);
/** Runs all the UnitTest objects with a specified name.
This calls runTests() for all the objects listed in UnitTest::getTestsWithName().
If you want to run the tests with a predetermined seed, you can pass that into
the randomSeed argument, or pass 0 to have a randomly-generated seed chosen.
*/
void runTestsWithName (const String& name, int64 randomSeed = 0);
/** Sets a flag to indicate whether an assertion should be triggered if a test fails.
This is true by default.
*/