DUnit Unable to create form. MDI forms are not currently active

Hi, I have a problem with my unit testing in Delphi XE3. I have a project consisting of 1 MDIForm and highlighting MDIChild forms, then the problem is that when I run the test in my MDIChild forms, I get this error:

TestAllDataSrouces: EInvalidOperation
at  $0064346F
SetUp FAILED: Cannot create form. No MDI forms are currently active

my installation method is as follows:

procedure TestTCustomerCard.SetUp;
begin
  FCustomerCard :=  TCustomerCard.Create(Application);
end;

What can I do to solve this error? so far i tried:

FCustomerCard :=  TCustomerCard.Create(Application.MainForm);

FCustomerCard :=  TCustomerCard.Create(nil);

and

procedure TestTCustomerCard.SetUp;
var
  a : TForm;
begin
  a := TForm.Create(nil);
  a.FormStyle := fsMDIForm;
  FCustomerCard :=  TCustomerCard.Create(a);
end;

and my test:

procedure TestTCustomerCard.TestAllDataSrouces;
var
  I: Integer;
begin
  for I := 0 to FCustomerCard.ComponentCount-1 do
  begin
    if (FCustomerCard.Components[i] is TcxLookupComboBox) then
    begin
      Check(TcxLookupComboBox(FCustomerCard.Components[i]).Properties.ListSource = nil,'Error no ListSource, Lookup: '+TcxLookupComboBox(FCustomerCard.Components[i]).Name+' Parent: '+TcxLookupComboBox(FCustomerCard.Components[i]).Parent.Name);
    end;
    if (FCustomerCard.Components[i] is TcxDBTextEdit) then
    begin
      Check(TcxDBTextEdit(FCustomerCard.Components[i]).DataBinding.DataSource = nil,'Error No DataSet, Text Edit: '+TcxDBTextEdit(FCustomerCard.Components[i]).Name+' Parent: '+TcxDBTextEdit(FCustomerCard.Components[i]).Parent.Name);
    end;
    if (FCustomerCard.Components[i] is TcxGridDBTableView) then
    begin
      Check(TcxGridDBTableView(FCustomerCard.Components[i]).DataController.DataSource = nil,'Error no Data Source, DB Grid View: '+TcxGridDBTableView(FCustomerCard.Components[i]).Name);
    end;
  end;
end;

Demo project: Here

+4
source share
3 answers

, , . . unit test.

, , . . . . . .

-

, , .

+5

. MDI, MDI. . DUnit. :

  • MDI. , .
  • MDI.
  • , .
+2

, " MDI".

, . testcase.

  • , MDI

    type TTestCustomerCard = class(TCustomerCard) end;

    .

  • dfm , CustomerCard.dfm, TestCustomerCard.dfm

  • TestCustomerCard.dfm ,

    FormStyle = fsMDIChild ( fsNormal ),

    object CustomerCard: TCustomerCard

    object TestCustomerCard: TTestCustomerCard

  • {$R TestCustomerCard.dfm }

  • SetUp

    FCustomerCard := TCustomerCard.Create(Application);

    FCustomerCard := TTestCustomerCard.CreateNew(Application); InitComponentRes( 'TTESTCUSTOMERCARD', FCustomerCard );

0

Source: https://habr.com/ru/post/1532033/


All Articles