Reputation: 27493
Currently I am using 2-level test hierarchy in DUnit (Test Project -> Test Case -> Test method; see example below). Is it possible to introduce 3rd level or even more levels?
Upvotes: 13
Views: 1220
Reputation: 5453
I build a hierarchy by putting backslashes in the `SuitePath'. For instance:
initialization
RegisterTests('Group1\Group2', [TExampleTests1.Suite,
TExampleTests2.Suite]);
RegisterTests('Group1\Group3', [TExampleTests3.Suite,
TExampleTests4.Suite]);
end.
In the end I get something like this:
A lot less mucking around than with David's way, and you can spread your group definitions across disparate units.
Upvotes: 11
Reputation: 612954
You can use test suites to create as many levels of nesting as you desire. The documentation offers the following example:
The
TestFramework
unit exposes theTTestSuite
class, the class that implements test suites, so you can create test hierarchies using more explicit code:The following function,
UnitTests
, creates a test suite and adds the two test classes to it:function UnitTests: ITestSuite; var ATestSuite: TTestSuite; begin ATestSuite := TTestSuite.create('Some trivial tests'); ATestSuite.addTest(TTestArithmetic.Suite); ATestSuite.addTest(TTestStringlist.Suite); Result := ATestSuite; end;
Yet another way to implement the above function would be:
function UnitTests: ITestSuite; begin Result := TTestSuite.Create( 'Some trivial tests', [TTestArithmetic.Suite, TTestStringlist.Suite] ); end;
In the above example, the
TTestSuite
constructor adds the tests in the passed array to the suite.You can register a test suite created in any of the above ways by using the same call you use to register individual test cases:
initialization RegisterTest('Simple Test', UnitTests); end.
When run with
GUITestRunner
, you will see the new hierarchy.
Upvotes: 9
Reputation: 36654
You can group related tests in test suites, which can be nested.
If you want to do it at run time, check out my "Open Component Test Framework (OpenCTF)" at sourceforge.
Upvotes: 3