Phoney is an iOS application to experiment with testing phone calls.
Making a phone call requires running on device, not simulator.
XCUITest can programmatically enter a phone number and start a phone call. Then use springboard app to handle alert tap "Call".
Use springboard app to tap "End call" button.
Before I found simple solution via springboard app, I thought of and tried some other approaches.
The test uses CXCallObserver delegate method callObserver(_ callObserver: callChanged:) The test can verify that a call hasConnected or hasEnded. But it's only an observer, doesn't have a method to end a call.
I prototyped test that uses addUIInterruptionMonitor and makes request to a raspberry pi web service end the call. The raspberry pi connects to a relay and a headphone breakout switch. The relay momentarily shorts the microphone and common contacts. This ended the call, but test kept failing with error "Application for Target Application 0x1c40af060 is not foreground."
This approach is very general, could be applied to many actions. I may prototype it later. For more info see Using a Raspberry Pi for iPhone Switch Control http://beepscore.com/using-raspberry-pi-for-iphone-switch-control/index.html
http://beepscore.com/xcuitest-ios-app-phone-call/index.html
http://beepscore.com/using-raspberry-pi-to-end-iphone-phone-call/
http://beepscore.com/using-raspberry-pi-for-iphone-switch-control/index.html
https://stackoverflow.com/questions/46322758/call-button-on-ui-testing
https://developer.apple.com/documentation/callkit/cxcallobserver
deprecated https://developer.apple.com/documentation/coretelephony/ctcallcenter https://developer.apple.com/documentation/coretelephony/ctcall
Note UITests won't run on simulator. This is expected. UITests require device with phone hardware to find and tap springboard phone call buttons.
To run unit UITests only (not unit tests), select scheme PhoneyUITests and type command-u. To run unit unit tests only (not UI tests), select scheme PhoneyTests and type command-u.