Hi, guys! This is my first post here. I've been trying to create a test case that deletes selected items from a TListView, using DUnitx and Delphi XE5. This is my method implementation:

Hi, guys! This is my first post here. I've been trying to create a test case that deletes selected items from a TListView, using DUnitx and Delphi XE5. This is my method implementation:

procedure TMyTest.DeleteItemsFromListView;
var
lv : TListView;
item : TListItem;
i : Integer;
begin

lv := TListView.Create(nil);
i := 0;

while i < 100 do
begin
item := lv.Items.Add; //error here!
item.Caption := 'Item' + IntToStr(i + 1);
item.Selected := ( (i div 2) = 0 );
Inc(i);
end;

TUtils.ExcluirItensSelecionados(lv); //My delete routine

Assert.AreEqual('50', IntToStr(lv.Items.Count));
Assert.AreEqual('Item99', lv.Items[lv.Items.Count - 1].Caption);
end;

What happens is, when I run the test, it fails during lv.Items.Add, complaining there's no parent. I tried to create a form and put it as the listview's parent but no success. I think dUnitX doesn't work well with VCL. Is that correct? Any suggestions? Thanks in advance!

Error:
---------------------------
Debugger Exception Notification
---------------------------
Project EleicoesTest.exe raised exception class EInvalidOperation with message 'Control '' has no parent window'.

Comments