Delphi XE3 での単体テストに問題があります。1 つの MDIForm と MDIChild フォームの割り当てで構成されるプロジェクトがあります。問題は、MDIChild フォームでテストを実行すると、次のエラーが発生することです。
TestAllDataSrouces: EInvalidOperation
at $0064346F
SetUp FAILED: Cannot create form. No MDI forms are currently active
私の Setup メソッドは次のようになります。
procedure TestTCustomerCard.SetUp;
begin
FCustomerCard := TCustomerCard.Create(Application);
end;
このエラーを解決するにはどうすればよいですか? これまで私は試しました:
FCustomerCard := TCustomerCard.Create(Application.MainForm);
FCustomerCard := TCustomerCard.Create(nil);
と
procedure TestTCustomerCard.SetUp;
var
a : TForm;
begin
a := TForm.Create(nil);
a.FormStyle := fsMDIForm;
FCustomerCard := TCustomerCard.Create(a);
end;
私のテストは次のとおりです。
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;
デモプロジェクト:こちら