I'm trying to check the state of an object after running a test. This state is contained in a set. Is it possible to pass the expected state to the test case using DUnitX Attributes, so that I can use the same test for all different inputs?
I tried to pass the set as a constant or as a set, but in my Test routine it always arrives as an empty set.
- Is this possible at all using attributes?
- How would you test if sets are identical?
Example code:
type
TResult = (resOK,resWarn,resError);
TResultSet = set of TResult;
const
cErrWarn : TResultSet = [resWarn];
type
[TestFixture]
TMyTest = class(TBaseTest)
[Test]
[TestCase('Demo1','InputA,[resWarn]')] // <-- tried as a set
[TestCase('Demo2','InputB,cErrWarn')] // <-- tried as a constant
procedure Test(Input:string; ExpectedResult: TResultSet);
end;
procedure TMyTest.Test(Input:string; ExpectedResult: TResultSet);
begin
// ExpectedResult is always the empty set []
RunTests(MyObject(Input));
Assert.AreEqual(ExpectedResult, MyObject.ResultSet);
end;
I also tried to define the Expected result as array, but then DUnitX doesn't even call the test anymore. Probably that's just "too much"
procedure Test(Input:string; ExpectedResult: array of TResult);
The best I could come up with so far was to use the following approach. Take a sample of up to three (insert your favourite integer here...) expected states and check for these separately. This is not really what I was hoping for, but it does the trick.
procedure Test(Input:string; R1,R2,R3: TResult);
Help is greatly appreciated. :)