Note that there are some explanatory texts on larger screens.

plurals
  1. POOCUnit or OCmock testing methodology for locally instantiated and scoped variables.
    primarykey
    data
    text
    <p>I am new to OCUnit and OCMock and would like to learn more about this testing methodology. </p> <p>I am aware of OCUnit and OCMock's capabilities to create stubs generate mock object etc... </p> <p>I have a particular use case that I have not been able to crack just yet. </p> <pre><code>-(bool) isGameCenterAvailable { // Check for presence of GKLocalPlayer API. Class gcClass = (NSClassFromString(@"GKLocalPlayer")); // The device must be running running iOS 4.1 or later. bool isIPAD = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad; NSString *reqSysVer = (isIPAD) ? @"4.2" : @"4.1"; NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending); return (gcClass &amp;&amp; osVersionSupported); } </code></pre> <p>Here are my issues with Unit Testing this:</p> <p>1) NSClassFromString(@"GKLocalPlayer") is a call to foundation.h with no ability to stub this that I know of.</p> <p>2) [[UIDevice currentDevice] systemVersion] are calls that are local to scope to the function. My method calls methods inside another Class (UIDevice) I would like to override their function call with stub to return a canned answer to exercise every path of this function. </p> <p>Not sure if Classes can be mocked if they are instantiated within the scope of the function under test. </p> <p>In addition how does one test Class methods like #1. </p> <p>Is refactoring the only answer here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload