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.
Other approaches to end call
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.
Headphone breakout switch
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."
Accessibility Switch Control
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
XCUITest an iOS app phone call
Using a Raspberry Pi to end an iPhone phone call
Using a Raspberry Pi for iPhone Switch Control
XCUITest phone call with help from springboard
How to detect call incoming programmatically
Appendix Run tests on device
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.