objective c - Don't repeat yourself while writing unit tests -
objective c - Don't repeat yourself while writing unit tests -
i have multiple singletons in app test this.
spschemeparser* (^createuniqueinstance) (void) = ^spschemeparser* (void) { homecoming [[spschemeparser alloc] init]; }; spschemeparser* (^getsharedmanager) (void) = ^spschemeparser* (void) { homecoming [spschemeparser sharedmanager]; }; // test singleton it(@"can create unique instance", ^{ expect(createuniqueinstance()).tonot.benil(); }); it(@"can create shared instance", ^{ expect(sut).tonot.benil(); }); it(@"returns same shared instance", ^{ expect(sut).to.equal(getsharedmanager()); }); it(@"returns different unique instance", ^{ expect(createuniqueinstance()).tonot.equal(createuniqueinstance()); }); it(@"returns unique instance different shared instance", ^{ expect(sut).tonot.equal(createuniqueinstance()); });
now, don't want have snippet copy-pasted in every unit test file testing singleton. wondering if there solution of have code written 1 time , used multiple tests.
objective-c unit-testing dry
Comments
Post a Comment