3

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?

mjn
  • 36,362
  • 28
  • 176
  • 378
Livius
  • 958
  • 1
  • 6
  • 19
  • Maybe this is not supported by DUnitX, because it is a framework for an **Unit Test** and you want to have an **Integration Test** :o) – Sir Rufo Nov 05 '15 at 09:15
  • 1
    @SirRufo DUnitX is not limited to unit tests. It's simply a mechanism for managing and running automated test cases. It can be used for far more than just unit tests. – David Heffernan Nov 05 '15 at 10:03
  • 2
    I have to agree with Livius here: Creating individual test cases with different parameters for the same method to test was near to trivial with the TestSuite approach of DUnit. Up to now I was not able to achieve the same simple approach for DUnitX. That's why I am also interested in a solution here. To give another real world example: I have a class that calculates the German income tax for a given set of parameters. The official program description contains a table with several reference values for different parameter sets. The test suite creates one test case for each parameter set. – Uwe Raabe Nov 05 '15 at 10:29
  • If it is easy with DUnit then why don't you stick with it? – Stefan Glienke Nov 05 '15 at 11:46
  • If you edit your question don't remove earlier edits: `[Test]` – Jan Doggen Nov 05 '15 at 13:38
  • @Stefan Glienke Yes, you have right. I supposed that DUnitX is successor of DUnit - but this is totally different framework. I see that better i will invest time to extend functionality of DUnit to support attributes for simple tests. – Livius Nov 05 '15 at 17:15
  • 1
    @Livius Save your time and use what I already did ;) http://stackoverflow.com/a/9006662/587106 – Stefan Glienke Nov 05 '15 at 17:25
  • You have my vote :) This is exactly what i plan make tomorrow - but it exist now, i really save time, thanks :) – Livius Nov 05 '15 at 17:36

2 Answers2

1

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.

mjn
  • 36,362
  • 28
  • 176
  • 378
1

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

ZeDalaye
  • 689
  • 7
  • 17
  • looks interesting i will test this. But why it use superobject? – Livius Aug 07 '18 at 19:23
  • I'm still using Delphi XE2 and I use extensively SuperObject for ages. I'm sure there are plenty other solutions to this problem of passing values to the test method. – ZeDalaye Aug 08 '18 at 06:50