Reputation: 20140
I got stuck with issue. I have OCUnit tests. I can run them successfully in iOS 7 simulator but I get EXC_BAD_ACCESS on iOS 6 simulator.
Here is screenshot form Xcode:
I'm using OCMockito
and OCHamcrest
.
Do you have any idea what was the cause? I'm trying to investigate and find out the cause.
Update:
Here code for test case (at least from log):
static NSString *const EMAIL = @"[email protected]";
static NSString *const PASSWORD = @"secret";
@interface MDLoginViewControllerTest : SenTestCase
@end
@implementation MDLoginViewControllerTest {
MDLoginViewController *controller;
MDLoginView *loginView;
UIWindow *window;
MDAlertManager *mockedAlertManager;
MDNetwork *mockedNetwork;
MDStorage *mockedStorage;
}
- (void)setUp
{
[super setUp];
mockedAlertManager = mock([MDAlertManager class]);
mockedNetwork = mock([MDNetwork class]);
mockedStorage = mock([MDStorage class]);
controller = [[MDLoginViewController alloc] initWithAlert:mockedAlertManager andNetwork:mockedNetwork andStorage:mockedStorage];
window = [[UIWindow alloc] init];
[window addSubview:controller.view];
}
# pragma mark - Test Helpers
- (void)login
{
[controller requestDiscoveryWithEmail:EMAIL andPassword:PASSWORD];
}
- (void)mockLoginView
{
loginView = mock([MDLoginView class]);
controller.loginView = loginView;
}
- (void (^)(NSError *))runControllerForgotPasswordForEmailAndReturnBlock
{
[controller recoverAccountPasswordForEmail:EMAIL];
MKTArgumentCaptor *captor = [MKTArgumentCaptor new];
[verify(mockedNetwork) forgotPasswordForEmail:EMAIL andCallback:[captor capture]];
void (^callback)(NSError *) = [captor value];
return callback;
}
# pragma mark - Tests itself
- (void)testAlertThatInputIsEmptyWhenLoginIsNil
{
[controller requestDiscoveryWithEmail:nil andPassword:@"pass"];
[verify(mockedAlertManager) showAlertMessage:EMPTY_DATA_MESSAGE withTitle:WRONG_DATA_TITLE];
[verifyCount(mockedNetwork, never()) discoveryWithEmail:anything() andPassword:anything() andCallback:anything()];
}
- (void)testAlertThatInputIsEmptyWhenLoginIsWhitespacesOnly
{
[controller requestDiscoveryWithEmail:@" " andPassword:@"pass"];
[verify(mockedAlertManager) showAlertMessage:EMPTY_DATA_MESSAGE withTitle:WRONG_DATA_TITLE];
[verifyCount(mockedNetwork, never()) discoveryWithEmail:anything() andPassword:anything() andCallback:anything()];
}
- (void)testAlertThatInputIsEmptyWhenPasswordIsNil
{
[controller requestDiscoveryWithEmail:@"[email protected]" andPassword:nil];
[verify(mockedAlertManager) showAlertMessage:EMPTY_DATA_MESSAGE withTitle:WRONG_DATA_TITLE];
[verifyCount(mockedNetwork, never()) discoveryWithEmail:anything() andPassword:anything() andCallback:anything()];
}
- (void)testAlertThatInputIsEmptyWhenPasswordIsWhitespacesOnly
{
[controller requestDiscoveryWithEmail:@"[email protected]" andPassword:@" "];
[verify(mockedAlertManager) showAlertMessage:EMPTY_DATA_MESSAGE withTitle:WRONG_DATA_TITLE];
[verifyCount(mockedNetwork, never()) discoveryWithEmail:anything() andPassword:anything() andCallback:anything()];
}
- (void)testAlertThatWrongEmailWhenEmailIsInvalid
{
[controller requestDiscoveryWithEmail:@"test" andPassword:@"passs"];
[verify(mockedAlertManager) showAlertMessage:ENTER_VALID_EMAIL_MESSAGE withTitle:WRONG_DATA_TITLE];
[verifyCount(mockedNetwork, never()) discoveryWithEmail:anything() andPassword:anything() andCallback:anything()];
}
- (void)testCallNetworkIfInputIsValid
{
[self login];
[verify(mockedNetwork) discoveryWithEmail:EMAIL andPassword:PASSWORD andCallback:anything()];
}
}
More images from Xcode:
Update:
Looks like issue is in method that is calling method from mock and one of argument is block which has strong reference on self
.
Here is code for this method:
- (void)requestDiscoveryWithEmail:(NSString *)email andPassword:(NSString *)password
{
...
// store email / password on view
_email = [email copy];
_password = [password copy];
[self.loginView showSpinner];
[self.network discoveryWithEmail:email
andPassword:password
andCallback:^(NSDictionary *response, NSError *error) {
// Hide the spinner
[self.loginView hideSpinner];
if (error) {
[self showError:error];
}
else {
if (![self isResponseComplete:response]) {
_response = [response copy];
[self.alertManager showAlertMessage:NSLocalizedString(@"We were unable to reach some services because maintenance or some issues", @"Unreachable services message")
withTitle:NSLocalizedString(@"Issues happened", @" Issues happened title")
andDelegate:self];
}
else {
[self processDiscoveryResponse:response];
}
}
}];
}
Upvotes: 1
Views: 389