Need to run Unit Tests on a background thread

I am writing/running my UnitTests using a slight adaptation of the standard JUCE approach… I run the tests with a Console App and the UnitTestRunner class which has #JUCE_UNIT_TESTS=1 defined in the Console App’s ProJucer file.

One of my tests interacts with the OnlineUnlockStatus::attemptWebserverUnlock method which needs to run on a background thread. I’m hitting the breakpoint in that method because the thread isn’t a background thread.

I’d like to run this test on a background thread, but it’s not clear which is the best approach that avoids messing with the existing thread model of the juce unit tests.

I’ve considered writing a custom test class to run each test in it inside a thread, which seems like it could create more issues than it solves. Another idea is to just spawn a single background thread in the console app’s Main and run the whole UnitTestRunner from that background thread.

Curious if anyone has encountered this issue or has any thoughts/suggestions. Thanks!

That’s an interesting problem that I haven’t run into before…

If you have multiple tests that require to be run on a background thread, then I would probably go with creating a class for it, like you suggested. But if it’s just this one test, then in the UnitTest::run() method I would probably just spin up a thread, start it, and block until the thread completes.

1 Like