[英]unit testing - How can I pass string with comma to a testcase in DUnitX
[英]Can I pass type parameters to a testcase in DUnitx?
我正在為我的FastCode項目編寫測試用例。
我已經編寫了一個通用測試儀,如下所示:
TTest<T> = record
private
class var Def: System.Generics.Defaults.IComparer<T>;
class var F: FastDefaults.TComparison<T>;
strict private
class function Slow(const Left, Right: T): integer; static;
class function Fast(const Left, Right: T): integer; static;
class constructor Init;
public
class procedure Test(const Left, Right: T); static;
end;
典型的測試用例如下所示:
[Test]
[TestCase('Single', '100.0,100.0')]
...many more testcases...
procedure TestSingle(const L,R: Single);
[Test]
[TestCase('Double', '100.0,100.0')]
...many more testcases... (identical to the one above).
procedure TestDouble(const L,R: double);
測試代碼通常如下(每種類型均重復):
procedure TestDefault.TestSingle(const L, R: Single);
begin
TTest<Single>.Test(L,R);
end;
我想做的是:
[Test]
[TestTypes('single,double,extended')]
[TestCase('description', '100.0,100.0')]
...many more test cases....
procedure Test<TC>(L,R: TC);
並對指定的類型進行測試,這樣我就不必寫太多樣板了。
可以在DUnitX中完成類似的事情嗎?
嘗試使您的測試類通用,並在要測試的每種具體類型中注冊您的測試類。
[TestFixture]
TMyTestObject<T> = class(TObject)
public
// Sample Methods
// Simple single Test
[Test]
procedure Test1;
// Test with TestCase Atribute to supply parameters.
[Test]
[TestCase('TestA','1,2')]
[TestCase('TestB','3,4')]
procedure Test2(const AValue1 : T; const AValue2 : T);
end;
//...
initialization
TDUnitX.RegisterTestFixture(TMyTestObject<integer>);
TDUnitX.RegisterTestFixture(TMyTestObject<double>);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.