I got unit tests working by adding my custom code that I want to test in .h and .cpp files to the UnitTestRunner project, using Projucer. I put my subclassed UnitTest code to a .h file and also added to UnitTestRunner project via Projucer; code is as per the comments in juce_UnitTest.h
In my UnitTest subclass have to point to where the actual code to test is, for me:
#include “./…/…/…/…/Documents/dev/juce/TailGunnerSr/Source/MixerDSP.h”
NOTE: This is ugly, I still have UnitTestRunner in the ~/JUCE folder
Now I have it working I’ll copy this project to a folder closer to my actual plugin code.
Need to add appropriate include files i.e. these are my 2 UnitTest classes (so far), so I include these in Main.cpp
#include “./MixerDSP-UnitTests.h”
#include “./More-UnitTests.h”
Just need to change the variable name at the end of the UnitTest class i.e.
static MyTestMixerDSP testDSP; // in file: MixerDSP-UnitTests.h
… and…
static MyTest2 testMore; // in file: More-UnitTests.h
Then to stop UnitTestRunner from running all the internal Juce tests I changed this in Main.cpp
if (args.size() == 0)
{
// runner.runAllTests();
runner.runTestsInCategory (“myDSP”);
runner.runTestsInCategory (“myOther”);
}
And set the actual category inside the UnitTest constructor of your subclassed UnitTest:
class MyTestMixerDSP : public UnitTest
{
public:
MyTestMixerDSP() : UnitTest (“Unit Tests: DSP - Tail Gunner Sr”, “myDSP”) {}
And since the expect() call doesn’t really tell you much when it fails I create a custom msg string, like this:
Declare msg string.
std::string msg = “”;
Can reuse ‘msg’ for all my tests.
msg = "Test 6: mixWetDry() is 70%: output = " + std::to_string(output) + ", result = " + std::to_string(result);
expect (output == result, msg);
It’s a fugly string. I was thinking I’ll make a util function that looks like:
testMsg(“Test 6: more text here”, output, result);
That spits out something like:
“Test 6: more text here. Expected X, Actual = Y”
BTW - This took me a few hours to figure out. I think I learned a few things in the process, however it was painful considering how quickly I got Jest working with a ReactJS project. Hope this helps. Feed back is welcome.