unit testing - Can I pass type parameters to a testcase in DUnitx? -
i'm writing testcases fastcode project.
i've written generic tester so:
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;
a typical test case looks like:
[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 1 above). procedure testdouble(const l,r: double);
the testing code typically follows (repeated every single type):
procedure testdefault.testsingle(const l, r: single); begin ttest<single>.test(l,r); end;
what do:
[test] [testtypes('single,double,extended')] [testcase('description', '100.0,100.0')] ...many more test cases.... procedure test<tc>(l,r: tc);
and have test run types stated, don't have write boilerplate.
can done in dunitx?
try make test class generic , register test class every single concrete type want test.
[testfixture] tmytestobject<t> = class(tobject) public // sample methods // simple single test [test] procedure test1; // test testcase atribute 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>);
Comments
Post a Comment