i'm in testing code within viewcontroller (that controls active depending on state of uiswitches etc) , decided go kiwi it, since using other low-level logic testing.
my expectation run tests this:
__block aviewcontroller *avc; it(@"(tokentextfield) should hidden if token switch set off", ^{ lvc.usetokenswitch.on = false; [[thevalue(avc.tokentextfield.hidden) should] equal:thevalue(yes)]; });
my problem initialisation of aviewcontroller. if did:
avc = [[aviewcontroller alloc] initwithnibname:@"aviewcontroller" bundle:nil];
i getting "aviewcontroller" without controls initialised, i'd have init each of them manually.
so have tried obtaining aviewcontroller doing this:
uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil]; avc = [storyboard instantiateviewcontrollerwithidentifier:@"aviewcontroller"];
yet results in error message:
nsinvalidargumentexception "could not find storyboard named 'mainstoryboard' in bundle nsbundle </applications/xcode.app/contents/developer/platforms/iphonesimulator.platform/developer/sdks/iphonesimulator6.1.sdk/developer/usr/bin> (loaded)" raised
i have included mainstoryboard in testing target, , included in "build phases" -> "copy bundle resources" , still nothing.
so wondering if possible instantiate viewcontroller storyboard in kiwi testing target? (as haven't seen examples of anywhere).
is approach wrong , should mocking viewcontroller?
am missing included in test target?
the problem you’re passing nil
bundle. can see in error message bundle it’s using. in unit test, want this:
class viewcontrollerclass = [myviewcontroller class]; nsstring *classname = nsstringfromclass(viewcontrollerclass); nsbundle *classbundle = [nsbundle bundleforclass:viewcontrollerclass]; myviewcontroller *viewcontroller = [[myviewcontroller alloc] initwithnibname:classname bundle:classbundle];
by looking bundle contains view controller’s class, you’ll nib file it.
for storyboards, code similar:
class viewcontrollerclass = [myviewcontroller class]; nsstring *classname = nsstringfromclass(viewcontrollerclass); nsbundle *classbundle = [nsbundle bundleforclass:viewcontrollerclass]; uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:classbundle]; myviewcontroller *viewcontroller = [storyboard instantiateviewcontrollerwithidentifier:classname];
(this assumes nib names , storyboard identifiers match class names. if don’t, change it.)
Comments
Post a Comment