Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on unit test #229

Open
benaneesh opened this issue Apr 21, 2017 · 12 comments
Open

Crash on unit test #229

benaneesh opened this issue Apr 21, 2017 · 12 comments

Comments

@benaneesh
Copy link

benaneesh commented Apr 21, 2017

Hi,

Installed using cocoapods withpod 'OneSignal', '~> 2.0', which installed version 2.5.2. This broke my unit tests. The tests themselves complete, but then crashes in the end.

*** Assertion failure in -[UNUserNotificationCenter initWithBundleIdentifier:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UserNotifications_Sim/UserNotifications-101.3.13/UNUserNotificationCenter.m:64
2017-04-21 15:29:03.264 xctest[65974:4144075] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: bundleIdentifier != nil'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000104039d4b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x0000000103a9b21e objc_exception_throw + 48
	2   CoreFoundation                      0x000000010403de42 +[NSException raise:format:arguments:] + 98
	3   Foundation                          0x000000010363066d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
	4   UserNotifications                   0x00000001089c19a6 -[UNUserNotificationCenter initWithBundleIdentifier:] + 210
	5   UserNotifications                   0x00000001089c1650 __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 106
	6   libdispatch.dylib                   0x0000000106d6312e _dispatch_client_callout + 8
	7   libdispatch.dylib                   0x0000000106d4de0e dispatch_once_f + 68
	8   UserNotifications                   0x00000001089c15e3 +[UNUserNotificationCenter currentNotificationCenter] + 45
	9   MyAppTests                          0x0000000110c488f3 +[OneSignalHelper registerAsUNNotificationCenterDelegate] + 51
	10  MyAppTests                          0x0000000110c400ea +[UIApplication(OneSignal) load] + 698
	11  libobjc.A.dylib                     0x0000000103a9d0f9 call_load_methods + 246
	12  libobjc.A.dylib                     0x0000000103a9dda3 load_images + 70
	13  ???                                 0x00000001033e5c5e 0x0 + 4349385822
	14  ???                                 0x00000001033f10aa 0x0 + 4349431978
	15  ???                                 0x00000001033f023a 0x0 + 4349428282
	16  ???                                 0x00000001033f02cf 0x0 + 4349428431
	17  ???                                 0x00000001033e89eb 0x0 + 4349397483
	18  ???                                 0x00000001033ecc20 0x0 + 4349414432
	19  libdyld.dylib                       0x0000000106da9ea4 dlopen + 59
	20  CoreFoundation                      0x0000000103fec419 _CFBundleDlfcnLoadBundle + 153
	21  CoreFoundation                      0x0000000103fec29d _CFBundleLoadExecutableAndReturnError + 333
	22  Foundation                          0x000000010358052e -[NSBundle loadAndReturnError:] + 521
	23  XCTest                              0x00000001034a9cc4 _XCTestMain + 465
	24  xctest                              0x00000001033dc922 xctest + 6434
	25  libdyld.dylib                       0x0000000106dac68d start + 1
	26  ???                                 0x0000000000000005 0x0 + 5
)
@jkasten2
Copy link
Member

@benaneesh The issue is that [UNUserNotificationCenter initWithBundleIdentifier:] doesn't seems to work correctly in a XCTest (non UI one).
https://forums.developer.apple.com/thread/54187

We recommend making sure you don't use OneSignal in the code your unit testing by wrapping your OneSignal calls.

We worked around this in our own Unit tests by swizzling this which you may use the same in your app.

- (id) overrideInitWithBundleIdentifier:(NSString*) bundle {
return self;
}

Thanks.

@lukacs-m
Copy link

I have encountered the same problem. Could you be more precise on how to fix or circumvent this issue.

Thank you

@hixfield
Copy link

same problem here!

@JanC
Copy link

JanC commented Oct 4, 2017

Hi,
I'm not using the OneSignal SDK but came across the same issue when working on my own SDK. I did not want to move my tests to a host application so the workaround I use in my tests is to mock the [UNUserNotificationCenter currentNotificationCenter] to return simply nil

In OCMock

id notificationCenterMock = OCMClassMock([UNUserNotificationCenter class]);
OCMStub(ClassMethod([notificationCenterMock currentNotificationCenter])).andReturn(nil);

Of course, this simply avoids the crash. If you really need a working UNUserNotificationCenter in your tests, a dependency injection would be a more elegant solution.

@fruitcoder
Copy link

I still have this issue and fixed it by early returning from load (just like the fix for IBDesignable crashes). Maybe #259 and #297 fix this already but they aren't merged.

@phuc-nguyen4-tiki
Copy link

I still have this issue, too. Run unit test in xcode 11. Please check again.

@albertpurnama
Copy link

Hey all! I'm experiencing the same issue on running unit test on cocoapod linting (also xcode 11), is this bug fix already in timeline for OneSignal team to fix @jkasten2 ?

@RodrigoLGuimaraes
Copy link

We are still experiencing this problem too. #297 Would fix it for us.

@albertpurnama
Copy link

This issue seems to happen to me with a slightly different error message. it said bundleProxy instead of bundleIdentifier

2020-12-16 20:27:27.785568-0800 xctest[82223:181950256] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: bundleProxy != nil'
    *** First throw call stack:
    (
    	0   CoreFoundation                      0x000000010384d29b __exceptionPreprocess + 331
    	1   libobjc.A.dylib                     0x0000000102de9735 objc_exception_throw + 48
    	2   CoreFoundation                      0x000000010384d022 +[NSException raise:format:arguments:] + 98
    	3   Foundation                          0x0000000102615b47 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
    	4   UserNotifications                   0x000000010ed9e951 -[UNUserNotificationCenter initWithBundleProxy:] + 292
    	5   UserNotifications                   0x000000010ed9e72c __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 81
    	6   libdispatch.dylib                   0x00000001059f1587 _dispatch_client_callout + 8
    	7   libdispatch.dylib                   0x00000001059f2d8e _dispatch_once_callout + 20
    	8   UserNotifications                   0x000000010ed9e6d8 +[UNUserNotificationCenter currentNotificationCenter] + 45
    	9   Cotter-Unit-Tests                   0x000000011aa2e4a7 +[OneSignalHelper registerAsUNNotificationCenterDelegate] + 38
    	10  Cotter-Unit-Tests                   0x000000011aa1dcac +[UIApplication(OneSignal) load] + 445
    	11  libobjc.A.dylib                     0x0000000102deadae call_load_methods + 234
    	12  libobjc.A.dylib                     0x0000000102debc04 load_images + 77
    	13  ???                                 0x00000001022ab068 0x0 + 4331319400
    	14  ???                                 0x00000001022b8532 0x0 + 4331373874
    	15  ???                                 0x00000001022b7704 0x0 + 4331370244
    	16  ???                                 0x00000001022b7798 0x0 + 4331370392
    	17  ???                                 0x00000001022ae162 0x0 + 4331331938
    	18  ???                                 0x00000001022b35ab 0x0 + 4331353515
    	19  libdyld.dylib                       0x0000000105a64214 dlopen + 171
    	20  CoreFoundation                      0x000000010385bf08 _CFBundleDlfcnLoadBundle + 152
    	21  CoreFoundation                      0x000000010373c689 _CFBundleLoadExecutableAndReturnError + 329
    	22  Foundation                          0x00000001025f569c -[NSBundle loadAndReturnError:] + 494
    	23  XCTest                              0x0000000102c1412e -[XCTestDriver _loadTestBundleFromURL:error:] + 145
    	24  XCTest                              0x0000000102c13404 -[XCTestDriver _prepareTestConfigurationAndIDESession] + 1207
    	25  XCTest                              0x0000000102c12f1d -[XCTestDriver run] + 23
    	26  XCTest                              0x0000000102ca0c28 _XCTestMain + 108
    	27  xctest                              0x000000010229bec5 main + 189@
    	28  libdyld.dylib                       0x0000000105a61551 start + 1
    )

@jkasten2 not sure what you meant by We recommend making sure you don't use OneSignal in the code your unit testing by wrapping your OneSignal calls

cmiiw, but I think +load from OneSignal runs whenever we import OneSignal, regardless whether I actually use the OneSignal calls or not. Method swizzling also won't work becausef swizzling that replaces the method executed on runtime will be executed later than the +load function.

Care to give examples on Swift? Thanks!

@acoomans
Copy link

+1 We're having the same issue

@emawby emawby added the Bug label Aug 12, 2022
@MorphToru
Copy link

+1 Having the same issue. Any update would be appreciated.

@PierreMardon
Copy link

+1 😬
Makes it impossible to wrap OneSignal related code in a framework (and have unit tests working).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests