Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI Tests + postNotificationName + never reaches observer + Xcode 7

I have UI Tests target for testing MyApp. To test specific MyApp conditions I need to post notifications from UI Test target to MyApp target. To post notification from UI Test target function I am using this:

NSNotificationCenter.defaultCenter().postNotificationName(name, object: nil, userInfo: aUserInfo)

It looks that this notification never reaches observer from UI Test target, but it works fine when posting this notification from MyApp target.

How to post notification from UI Target to MyApp target?

Using Xcode 7.

like image 887
Ramis Avatar asked Nov 10 '15 15:11

Ramis


1 Answers

Have similar problem (trying to ensure NSNotification is being posted after certain UI action). Did small research on this.

NSNotification not being received because UI test and app are running in different processes. NSNotification cannot go through process bounds, and NSDistributedNotificationServer is not available on iOS. So, currently there is no default and easy way to post NSNotifications between UI test suite and app instance.

However, there is some ways to communicate between processes, and maybe write small wrapper or even NSDistributedNotificationCenter iOS surrogate for testing purposes. Check out this great article from Realm: https://academy.realm.io/posts/thomas-goyne-fast-inter-process-communication/

like image 184
Cemen Avatar answered Oct 20 '22 02:10

Cemen