c# - How to set DateTime as ValuesAttribute to unit test? -
i want this
[test] public void test([values(new datetime(2010, 12, 01), new datetime(2010, 12, 03))] datetime from, [values(new datetime(2010, 12, 02), new datetime(2010, 12, 04))] datetime to) { ilist<myobject> result = mymethod(from, to); assert.areequal(1, result.count); } but following error regarding parameters
an attribute argument must constant expression, typeof expression or array creation expression of an
any suggestions?
update: nice article parameterized tests in nunit 2.5
http://www.pgs-soft.com/new-features-in-nunit-2-5-part-1-parameterized-tests.html
an alternative bloating unit test, can offload creation of testcasedata using testcasesource attribute.
testcasesource attribute lets define method in class invoked nunit , data created in method passed test case.
this feature available in nunit 2.5 , can learn more here...
[testfixture] public class datevaluestest { [testcasesource(typeof(datevaluestest), "datevaluesdata")] public bool monthisdecember(datetime date) { var month = date.month; if (month == 12) return true; else return false; } private static ienumerable datevaluesdata() { yield return new testcasedata(new datetime(2010, 12, 5)).returns(true); yield return new testcasedata(new datetime(2010, 12, 1)).returns(true); yield return new testcasedata(new datetime(2010, 01, 01)).returns(false); yield return new testcasedata(new datetime(2010, 11, 01)).returns(false); } }
Comments
Post a Comment