Based on joern amazing article, I took a step forward and found a way to programmatically interact with the received notification, as it is identified by the XCTest framework as a XCUIElement.
As we can get a reference to the Sprinboard
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
For example, when putting the app on the background we could get a reference to the received notification (while it is being displayed in the top of the screen) like this:
let notification = springboard.otherElements["NotificationShortLookView"]
Allowing us to tap the notification:
notification.tap()
Pull it down to see its actions (if any available. Also by doing this could allow us to see the content of a Rich Notification):
notification.swipeDown()
Interact with its actions:
let action = springboard.buttons["ACTION BUTTON TITLE"]
action.tap()
And even interact with a Text Input notification action (in the example, by getting a reference to the notification textfield by its placeholder, which you can define in your code):
let notificationTextfield = springboard.textFields["Placeholder"]
notificationTextfield.typeText("this is a test message")
At last, you can also get a reference to the notification's close button in order to dismiss it:
let closeButton = springboard.buttons["Dismiss"]
closeButton.tap()
By being able to automate this interactions we could test, for example analytics, as described in this article.