The advantage of having the tests as a window within the main program is that the tests can be run from the Main Menu at any point during the program's execution. Running the tests at various times throughout the program's execution makes it easier to spot errors which crop up over time, not merely at the program's initial execution.
It's nice to be able to say, at any point in time, "I think I'll run a Test right now, just to see if anything comes up Red."
Here's how I did it: I created a ActionList TAction item and named it "actTest". I created a MainMenu item named "Test", and assigned it the TAction actTest. I created the TestCase1 unit from the Lazarus Menu, "New..." | Module | FPCUnit Test Case. I added "TestCase1, GuiTestRunner" to the uses clause of my main program. With the Project Inspector, I added "fpcunitrunner" as a Required Package to my project.
I assigned the keyboard shortcut Ctrl+T to the Test Menuitem. So I can quickly run a test by pressing Ctrl+T then F9.
Although probably unnecessary, I also created an inherited class from TGuiTestRunner, just so I could create my own FormClose method, to ensure that I don't create more than 1 instance of the MyGuiTestRunner object.
If you don't want end users to be able to see the tests, you could just hide the "Test" menuitem before compiling your distribution version. However, it might give customers confidence in your program if they are able to run tests, too. Further, a customer running a test might be able to give you insight about program bugs later.
unit MyUnit1
uses ... TestCase1, GuiTestRunner ...
type
{ TMyGuiTestRunner }
TMyGuiTestRunner = class(TGuiTestRunner)
procedure FormClose(Sender: Tobject; var Closeaction: Tcloseaction);
end;
{ TfrMain, my program's main form }
TfrMain = class(TForm)
...
actTest: TAction;
procedure actTestExecute(Sender: TObject);
...
var
MyGuiTestRunner: TMyGUITestRunner;
procedure TMyGuiTestRunner.FormClose(Sender: Tobject; var Closeaction: Tcloseaction);
begin
CloseAction := caFree;
MyGuiTestRunner := nil;
end;
procedure TfrMain.actTestExecute(Sender: TObject);
begin
if (MyGuiTestRunner = nil) then
Application.CreateForm(TGUITestRunner, MyGuiTestRunner);
MyGuiTestRunner.Show;
end;