I use DUnit. It has an VCL GUITestRunner and a console TextTestRunner.
In an unit used by both Firemonkey and VCL Forms applications I would like to achieve the following:
- If Firemonkey app, if target is OS X, and executing on OS X -> TextTestRunner
- If Firemonkey app, if target is 32-bit Windows, executing on Windows -> AllocConsole + TextTestRunner
- If VCL app -> GUITestRunner
{$IFDEF MACOS}
TextTestRunner.RunRegisteredTests; // Case 1
{$ELSE}
{$IFDEF MSWINDOWS}
AllocConsole;
{$ENDIF}
{$IFDEF FIREMONKEY_APP} // Case 2 <--------------- HERE
TextTestRunner.RunRegisteredTests;
{$ELSE} // Case 3
GUITestRunner.RunRegisteredTests;
{$IFEND}
{$ENDIF}
Which is the best way to make Case 2 work?
There are no built in conditionals that tell you whether the project’s
FrameworkType, as specified in the .dproj file, is VCL or FMX. To the very best of my knowledge you cannot switch on that setting in code. Remember also that it is perfectly possible, although certainly not mainstream, to have an application that uses both VCL and FMX. It’s really not an either or condition.So I recommend that you declare your own conditional define that controls whether you use the GUI runner or the text runner.
In fact, you presumably already have some sort of a mechanism to do this. You code names the unit
GUITestRunner. So that means it must be in ausesin the same file as the code in the question. How did you conditionally includeGUITestRunnerin the uses clause?Note: The same question has been asked on the Embarcadero forums: https://newsgroups.embarcadero.com/message.jspa?messageID=400077