Problem/Motivation
In #3477634: Ensure run-tests.sh and PHPUnit CLI run with the same list of tests to be executed, we introduced a test checking equality between PHPUnit and TestDiscovery test discovery lists and fails if they differ.
We used a shell process to run the PHPUnit CLI for this purpose, and interpreted the output XML file.
PHPUnit also provides an API to retrieve the test list via PHP, avoiding the subprocess execution.
Using directly the API has a potential to eventually drop Drupal's own test discovery process.
Proposed resolution
For now, just add a check for the result of the API calls. Keep both CLI and API checks.
Dropping Drupal's TestDiscovery is left to a follow-up once we are confident we no longer need that.