Livius
Livius

Reputation: 956

Create list of test dynamically

i use DUnitX in Delphi but i got stuck. How can i create list of tests dynamically?

e.g. i have list of sql and need to test them all like

for i:= 0 to List.Count do
  begin
    AddTest(List[i].SQL, List[i].Info, List[i].MaxTime);
  end;

for one method this is simple

[Test]
procedure TestSingleSQL;

implementation

procedure TestSingleSQL;
Var tick: Cardinal;
begin
  tic:= GetTickCount;
  Connection.Execute(SQL);
  Assert.IsTrue(Abs(GetTickCount-Tick)<MaxTime);
end

But if i need list of tests then attribute is inadequate. RepeatTest attribute is also inadequate, because if one test failed inside then whole test is stopped, but i need to run all sql

any advice

EDIT1

in DUnit (Without X) this was possible like this

function CreateDBTests: ITestSuite;
Var i: Integer;
  baza: String;
  TS_Connected, TS_SumyZlecFakt, TS_WPLATY, TS_KONTRAHENT: ITestSuite;
begin
  Result:= TTestSuite.Create('Lista baz');

  TS_Connected:= TTestSuite.Create('Połączenia');
  TS_SumyZlecFakt:= TTestSuite.Create('SyumyZlecFakt');
  TS_WPLATY:= TTestSuite.Create('Wpłaty');
  TS_KONTRAHENT:= TTestSuite.Create('Kontrahent');
  for i:= 0 to ListaBaz.Count-1 do
    begin
      baza:= ListaBaz[i];

      TS_Connected.AddTest(TTestConnected.CreateDBListTest(baza));
      TS_SumyZlecFakt.AddTest(TestSumyZlecFakt.CreateDBListTest(baza));
      TS_WPLATY.AddTest(TestWplaty.CreateDBListTest(baza));
      TS_KONTRAHENT.AddTest(TestKontrahent.CreateDBListTest(baza));
    end;

  Result.AddSuite(TS_Connected);
  Result.AddSuite(TS_SumyZlecFakt);
  Result.AddSuite(TS_WPLATY);
  Result.AddSuite(TS_KONTRAHENT);
end;

what is equivalent in DUnitX?

Upvotes: 3

Views: 855

Answers (2)

ZeDalaye
ZeDalaye

Reputation: 709

I succeeded in some way by declaring test cases in a JSON file and hooking into the DUnitX plugin system :

https://github.com/VSoftTechnologies/DUnitX/issues/211#issuecomment-411082097

Upvotes: 1

mjn
mjn

Reputation: 36664

According to this description DunitX is attribute-driven. It is not meant to be a drop-in replacement (or an extension) for DUnit. So I guess it does not support dynamic test case creation.

p.s. I am the author of an open source component test framework which is based on DUnit and makes heavy use of dynamic test generation.

Upvotes: 1

Related Questions