Is it possible to use namespaces in dunitx in such a way that all test fixtures under a namespace are enclosed by one pair of setup/teardown routines? (Similar to the SetupFixture attribute in nunit, http://www.nunit.org/index.php?p=setupFixture&r=2.5.5).
I tried to use the following unit names/namespaces:
Tests.MyFixture.pas for the TMyFixtureInitializer class with the common setup and teardown methods
Tests.MyFixture.MyTestUnit1.pas and Tests.MyFixture.MyTestUnit2.pas for the actual test classes.
I ran into the following problems:
TMyFixtureInitializer.SetupFixture and TeardownFixture are not executed when the class itself does not contain any test routine.
After adding a dummy test in TMyFixtureInitializer, the SetupFixture and TeardownFixture routines are called, but after the tests in Tests.MyFixture.MyTestUnit1 and Tests.MyFixture.MyTestUnit2.
When I set the SetupFixture attribute on the constructor, and the TeardownFixture attribute on the destructor of TMyFixtureInitializer, they are executed before and after all tests, ignoring the namespaces altogether.
Tests.MyFixture.pas:
unit Tests.MyFixture;
interface
uses
DUnitX.TestFramework;
type
[TestFixture]
TMyFixtureInitializer = class(TObject)
public
[SetupFixture]
procedure SetupMyFixture;
[TeardownFixture]
procedure TeardownMyFixture;
end;
implementation
{ TMyFixtureInitializer }
procedure TMyFixtureInitializer.SetupMyFixture;
begin
Self.Log('initialize a lot of stuff ...');
end;
procedure TMyFixtureInitializer.TeardownMyFixture;
begin
Self.Log('cleanup a lot of stuff ...');
end;
initialization
TDUnitX.RegisterTestFixture(TMyFixtureInitializer);
end.
Tests.MyFixture.MyTestUnit1.pas:
unit Tests.MyFixture.MyTestUnit1;
interface
uses
DUnitX.TestFramework;
type
[TestFixture]
TestClass1 = class(TObject)
public
[Test]
procedure Test;
end;
implementation
{ TestClass1 }
procedure TestClass1.Test;
begin
end;
initialization
TDUnitX.RegisterTestFixture(TestClass1);
end.
(Source of Tests.MyFixture.MyTestUnit2.pas is analogous).
Does anyone have an example of how to use namespaces to organize initialization and cleanup?