Can I pass a set to a test case in DUnitX?

后端 未结 2 1676
眼角桃花
眼角桃花 2021-02-07 06:20

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 Attri

2条回答
  •  -上瘾入骨i
    2021-02-07 07:10

    Add this conversion function to DUnitX.Utils and put it into the Conversions matrix for tkUString to tkSet (due to limitations of StringToSet and TValue this only works for sets up to 32 elements, for larger sets of up to 256 elements there is more code required though):

    function ConvStr2Set(const ASource: TValue; ATarget: PTypeInfo; out AResult: TValue): Boolean;
    begin
      TValue.Make(StringToSet(ATarget, ASource.AsString), ATarget, AResult);
      Result := True;
    end;
    

    Also you need to use a different separator char for the parameters or it will split them wrong:

    [TestCase('Demo1','InputA;[resWarn,resError]', ';')]
    

提交回复
热议问题