I was trying to create unit tests for the classes I’m writing. Looking at the UnitTest and UnitTestRunner classes this is what I’ve figured out. Wanted to know if this is the normal way of doing it in JUCE or is there a better way.
Initially I was thinking I’ll create a separate project for unit tests. But that didn’t work since the classes to test was in another project which used one ‘…/JuceLibraryCode/JuceHeader.h’ and the tests used another which caused conflits while using the classes in test project.
So I’ve modified the main application project itself as below.
- Added a new macro JUCEApplication implementation file
- Use the macro in JUCEApplication::initialise
- Run the tests if its set to 1
- Else create the MainWindow and start the application.
But the problem with this is, it forces me to add the macro in all the class files. Is there a way to setup the macro once which can be used across different class files? May be there is altogether a better way to do this. But I haven’t figured that out yet.
I wanted to run the test only when I wanted and not whenever I compile and run the application.