unit testing - Use AutoData and MemberData attributes in XUnit test -
i'm facing interesting problem. found out autodataattribute can use minimize "arrange" part of test (dependencies passed through ctor). awesome!
example:
public class automoqdataattribute : autodataattribute { public automoqdataattribute() : base(new fixture().customize(new automoqcustomization())) { } } [theory, automoqdata] public void process_validcontext_callsk2workflows( [frozen]mock<ik2datasource> k2, [frozen]mock<iappconfiguration> config, prbatchapprovebroker sut) { (...) } now want use great feature and inject own data theory:
[theory, automoqdata, memberdata("data")] public void extractpayments_emptyinvoicenumber_ignoresrecordswithemptyinvoicenumber( [frozen]mock<iexceldatasource> xls, sunsystemexceldatasource sut, list<row> rows, int expectedcount) { (...) } problem: autodata attribute generate random data me. way found rid of autodata attribute , use memberdata. if that, need handle object instantiations myself :)...
is there way pass classes and "hard-coded" data @ same time?
thank u, seb
is there way pass classes and "hard-coded" data @ same time?
one way of doing supplying inline values through attribute, , have autofixture fill rest of them.
[theory, inlineautomoqdata(3)] public void extractpayments_emptyinvoicenumber_ignoresrecordswithemptyinvoicenumber( int expectedcount, [frozen]mock<iexceldatasource> xls, sunsystemexceldatasource sut, list<row> rows) { // expectedcount 3. } note had move expectedcount in order first parameter, , make use of custom inlineautomoqdata attribute defined as:
internal class automoqdataattribute : autodataattribute { internal automoqdataattribute() : base(new fixture().customize(new automoqcustomization())) { } } internal class inlineautomoqdataattribute : compositedataattribute { internal inlineautomoqdataattribute(params object[] values) : base( new dataattribute[] { new inlinedataattribute(values), new automoqdataattribute() }) { } }
Comments
Post a Comment