diff --git a/core/lib/Drupal/Core/Test/JUnitConverter.php b/core/lib/Drupal/Core/Test/JUnitConverter.php
new file mode 100644
index 0000000000..f539a3ffbe
--- /dev/null
+++ b/core/lib/Drupal/Core/Test/JUnitConverter.php
@@ -0,0 +1,117 @@
+<?php
+
+namespace Drupal\Core\Test;
+
+/**
+ * Converts JUnit XML to a form Drupal SimpleTest can use.
+ *
+ * This is mainly for converting PHPUnit output.
+ */
+class JUnitConverter {
+
+  /**
+   * Converts PHPUnit's JUnit XML output to an array.
+   *
+   * @param int $test_id
+   *   The current test ID.
+   * @param string $phpunit_xml_file
+   *   Path to the PHPUnit XML file.
+   *
+   * @return array[]
+   *   The results as array of rows in a format that can be inserted into
+   *   {simpletest}.
+   */
+  public static function xmlToRows($test_id, $phpunit_xml_file) {
+    $contents = @file_get_contents($phpunit_xml_file);
+    if (!$contents) {
+      return;
+    }
+    $records = [];
+    $testcases = static::findTestcases(new \SimpleXMLElement($contents));
+    foreach ($testcases as $testcase) {
+      $records[] = static::testcaseToSimpletestRow($test_id, $testcase);
+    }
+    return $records;
+  }
+
+  /**
+   * Finds all test cases recursively from a test suite list.
+   *
+   * @param \SimpleXMLElement $element
+   *   The PHPUnit xml to search for test cases.
+   * @param \SimpleXMLElement $parent
+   *   (Optional) The parent of the current element. Defaults to NULL.
+   *
+   * @return array
+   *   A list of all test cases.
+   */
+  public static function findTestcases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) {
+    $testcases = [];
+
+    if (!isset($parent)) {
+      $parent = $element;
+    }
+
+    if ($element->getName() === 'testcase' && (int) $parent->attributes()->tests > 0) {
+      // Add the class attribute if the testcase does not have one. This is the
+      // case for tests using a data provider. The name of the parent testsuite
+      // will be in the format class::method.
+      if (!$element->attributes()->class) {
+        $name = explode('::', $parent->attributes()->name, 2);
+        $element->addAttribute('class', $name[0]);
+      }
+      $testcases[] = $element;
+    }
+    else {
+      foreach ($element as $child) {
+        $file = (string) $parent->attributes()->file;
+        if ($file && !$child->attributes()->file) {
+          $child->addAttribute('file', $file);
+        }
+        $testcases = array_merge($testcases, simpletest_phpunit_find_testcases($child, $element));
+      }
+    }
+    return $testcases;
+  }
+
+  /**
+   * Converts a PHPUnit test case result to a {simpletest} result row.
+   *
+   * @param int $test_id
+   *   The current test ID.
+   * @param \SimpleXMLElement $testcase
+   *   The PHPUnit test case represented as XML element.
+   *
+   * @return array
+   *   An array containing the {simpletest} result row.
+   */
+  public static function testcaseToSimpletestRow($test_id, \SimpleXMLElement $testcase) {
+    $message = '';
+    $pass = TRUE;
+    if ($testcase->failure) {
+      $lines = explode("\n", $testcase->failure);
+      $message = $lines[2];
+      $pass = FALSE;
+    }
+    if ($testcase->error) {
+      $message = $testcase->error;
+      $pass = FALSE;
+    }
+
+    $attributes = $testcase->attributes();
+
+    $record = [
+      'test_id' => $test_id,
+      'test_class' => (string) $attributes->class,
+      'status' => $pass ? 'pass' : 'fail',
+      'message' => $message,
+      // @todo: Check on the proper values for this.
+      'message_group' => 'Other',
+      'function' => $attributes->class . '->' . $attributes->name . '()',
+      'line' => $attributes->line ?: 0,
+      'file' => $attributes->file,
+    ];
+    return $record;
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
new file mode 100644
index 0000000000..a21e7f427f
--- /dev/null
+++ b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
@@ -0,0 +1,238 @@
+<?php
+
+namespace Drupal\Core\Test;
+
+use Drupal\Core\Database\Database;
+use Drupal\Tests\Listeners\SimpletestUiPrinter;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\Process\PhpExecutableFinder;
+
+/**
+ * Run PHPUnit-based tests.
+ *
+ * Drupal's test runners require a way to run PHPUnit-based tests and offer data
+ * that can be converted from JUnit to a form SimpleTest can use.
+ *
+ * This class encapsulates that process. Example:
+ * @code
+ * $runner = PhpUnitTestRunner::create(\Drupal::getContainer());
+ * $results = $runner->runTests($test_id, $test_list['phpunit']);
+ * @endcode
+ */
+class PhpUnitTestRunner {
+
+  /**
+   * Path to the working directory.
+   *
+   * JUnit log files will be stored in this directory.
+   *
+   * @var string
+   */
+  protected $workingDirectory;
+
+  /**
+   * Path to the application root.
+   *
+   * @var string
+   */
+  protected $appRoot;
+
+  /**
+   * Factory method to inject the container-based dependencies.
+   *
+   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
+   *   Container to inject.
+   *
+   * @return static
+   *   Newly-created test runner object.
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      (string) $container->get('app.root'),
+      (string) $container->get('file_system')->realpath('public://simpletest')
+    );
+  }
+
+  /**
+   * Constructs a test runner.
+   *
+   * @param string $app_root
+   *   Path to the application root.
+   * @param string $working_directory
+   *   Path to the working directory. JUnit log files will be stored in this
+   *   directory.
+   */
+  public function __construct($app_root, $working_directory) {
+    $this->appRoot = $app_root;
+    $this->workingDirectory = $working_directory;
+  }
+
+  /**
+   * Returns the path to use for PHPUnit's --log-junit option.
+   *
+   * @param int $test_id
+   *   The current test ID.
+   *
+   * @return string
+   *   Path to the PHPUnit XML file to use for the current $test_id.
+   */
+  public function xmlLogFilepath($test_id) {
+    return $this->workingDirectory . '/phpunit-' . $test_id . '.xml';
+  }
+
+  /**
+   * Returns the path to core's phpunit.xml.dist configuration file.
+   *
+   * @return string
+   *   The path to core's phpunit.xml.dist configuration file.
+   */
+  public function phpUnitConfigurationFilepath() {
+    return $this->appRoot . '/core/phpunit.xml.dist';
+  }
+
+  /**
+   * Returns the command to run PHPUnit.
+   *
+   * @return string
+   *   The command that can be run through exec().
+   */
+  public function phpUnitCommand() {
+    // Load the actual autoloader being used and determine its filename using
+    // reflection. We can determine the vendor directory based on that filename.
+    $autoloader = require $this->appRoot . '/autoload.php';
+    $reflector = new \ReflectionClass($autoloader);
+    $vendor_dir = dirname(dirname($reflector->getFileName()));
+
+    // The file in Composer's bin dir is a *nix link, which does not work when
+    // extracted from a tarball and generally not on Windows.
+    $command = $vendor_dir . '/phpunit/phpunit/phpunit';
+    if (substr(PHP_OS, 0, 3) == 'WIN') {
+      // On Windows it is necessary to run the script using the PHP executable.
+      $php_executable_finder = new PhpExecutableFinder();
+      $php = $php_executable_finder->find();
+      $command = $php . ' -f ' . escapeshellarg($command) . ' --';
+    }
+    return $command;
+  }
+
+  /**
+   * Executes the PHPUnit command.
+   *
+   * @param string[] $unescaped_test_classnames
+   *   An array of test class names, including full namespaces, to be passed as
+   *   a regular expression to PHPUnit's --filter option.
+   * @param string $phpunit_file
+   *   A filepath to use for PHPUnit's --log-junit option.
+   * @param int $status
+   *   (optional) The exit status code of the PHPUnit process will be assigned
+   *   to this variable.
+   * @param string[] $output
+   *   (optional) The output by running the phpunit command. If provided, this
+   *   array will contain the lines output by the command.
+   *
+   * @return string
+   *   The results as returned by exec().
+   */
+  public function runCommand(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL) {
+    global $base_url;
+    // Setup an environment variable containing the database connection so that
+    // functional tests can connect to the database.
+    putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl());
+
+    // Setup an environment variable containing the base URL, if it is
+    // available.
+    // This allows functional tests to browse the site under test. When running
+    // tests via CLI, core/phpunit.xml.dist or core/scripts/run-tests.sh can set
+    // this variable.
+    if ($base_url) {
+      putenv('SIMPLETEST_BASE_URL=' . $base_url);
+      putenv('BROWSERTEST_OUTPUT_DIRECTORY=' . \Drupal::service('file_system')->realpath('public://simpletest'));
+    }
+    $phpunit_bin = $this->phpUnitCommand();
+
+    $command = [
+      $phpunit_bin,
+      '--log-junit',
+      escapeshellarg($phpunit_file),
+      '--printer',
+      escapeshellarg(SimpletestUiPrinter::class),
+    ];
+
+    // Optimized for running a single test.
+    if (count($unescaped_test_classnames) == 1) {
+      $class = new \ReflectionClass($unescaped_test_classnames[0]);
+      $command[] = escapeshellarg($class->getFileName());
+    }
+    else {
+      // Double escape namespaces so they'll work in a regexp.
+      $escaped_test_classnames = array_map(function($class) {
+        return addslashes($class);
+      }, $unescaped_test_classnames);
+
+      $filter_string = implode("|", $escaped_test_classnames);
+      $command = array_merge($command, [
+        '--filter',
+        escapeshellarg($filter_string),
+      ]);
+    }
+
+    // Need to change directories before running the command so that we can use
+    // relative paths in the configuration file's exclusions.
+    $old_cwd = getcwd();
+    chdir($this->appRoot . "/core");
+
+    // exec in a subshell so that the environment is isolated when running tests
+    // via the simpletest UI.
+    $ret = exec(join($command, " "), $output, $status);
+
+    chdir($old_cwd);
+    putenv('SIMPLETEST_DB=');
+    if ($base_url) {
+      putenv('SIMPLETEST_BASE_URL=');
+      putenv('BROWSERTEST_OUTPUT_DIRECTORY=');
+    }
+    return $ret;
+  }
+
+  /**
+   * Executes PHPUnit tests and returns the results of the run.
+   *
+   * @param int $test_id
+   *   The current test ID.
+   * @param string[] $unescaped_test_classnames
+   *   An array of test class names, including full namespaces, to be passed as
+   *   a regular expression to PHPUnit's --filter option.
+   * @param int $status
+   *   (optional) The exit status code of the PHPUnit process will be assigned
+   *   to this variable.
+   *
+   * @return array
+   *   The parsed results of PHPUnit's JUnit XML output, in the format of
+   *   {simpletest}'s schema.
+   */
+  public function runTests($test_id, array $unescaped_test_classnames, &$status = NULL) {
+    $phpunit_file = $this->xmlLogFilepath($test_id);
+    // Store ouptut from our test run.
+    $output = [];
+    $this->runCommand($unescaped_test_classnames, $phpunit_file, $status, $output);
+
+    $rows = [];
+    if ($status == TestStatus::PASS) {
+      $rows = JUnitConverter::xmlToRows($test_id, $phpunit_file);
+    }
+    else {
+      $rows[] = [
+        'test_id' => $test_id,
+        'test_class' => implode(",", $unescaped_test_classnames),
+        'status' => TestStatus::label($status),
+        'message' => 'PHPunit Test failed to complete; Error: ' . implode("\n", $output),
+        'message_group' => 'Other',
+        'function' => implode(",", $unescaped_test_classnames),
+        'line' => '0',
+        'file' => $phpunit_file,
+      ];
+    }
+    return $rows;
+  }
+
+}
diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index 27034dc219..0e56f0566f 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -6,16 +6,14 @@
  */
 
 use Drupal\Core\Asset\AttachedAssetsInterface;
-use Drupal\Core\Database\Database;
 use Drupal\Core\Render\Element;
 use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Test\JUnitConverter;
+use Drupal\Core\Test\PhpUnitTestRunner;
 use Drupal\simpletest\TestBase;
 use Drupal\Core\Test\TestDatabase;
 use Drupal\simpletest\TestDiscovery;
-use Drupal\Tests\Listeners\SimpletestUiPrinter;
 use PHPUnit\Framework\TestCase;
-use Symfony\Component\Process\PhpExecutableFinder;
-use Drupal\Core\Test\TestStatus;
 
 /**
  * Implements hook_help().
@@ -118,8 +116,9 @@ function _simpletest_format_summary_line($summary) {
 /**
  * Runs tests.
  *
- * @param $test_list
- *   List of tests to run.
+ * @param array[] $test_list
+ *   List of tests to run. The top level is keyed by type of test, either
+ *   'simpletest' or 'phpunit'. Under that is an array of class names to run.
  *
  * @return string
  *   The test ID.
@@ -181,28 +180,13 @@ function simpletest_run_tests($test_list) {
  * @return array
  *   The parsed results of PHPUnit's JUnit XML output, in the format of
  *   {simpletest}'s schema.
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before 9.0.0. Use
+ *   \Drupal\Core\Test\PhpUnitTestRunner::runTests().
  */
 function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames, &$status = NULL) {
-  $phpunit_file = simpletest_phpunit_xml_filepath($test_id);
-  simpletest_phpunit_run_command($unescaped_test_classnames, $phpunit_file, $status, $output);
-
-  $rows = [];
-  if ($status == TestStatus::PASS) {
-    $rows = simpletest_phpunit_xml_to_rows($test_id, $phpunit_file);
-  }
-  else {
-    $rows[] = [
-      'test_id' => $test_id,
-      'test_class' => implode(",", $unescaped_test_classnames),
-      'status' => TestStatus::label($status),
-      'message' => 'PHPunit Test failed to complete; Error: ' . implode("\n", $output),
-      'message_group' => 'Other',
-      'function' => implode(",", $unescaped_test_classnames),
-      'line' => '0',
-      'file' => $phpunit_file,
-    ];
-  }
-  return $rows;
+  $runner = PhpUnitTestRunner::create(\Drupal::getContainer());
+  return $runner->runTests($test_id, $unescaped_test_classnames, $status);
 }
 
 /**
@@ -275,9 +259,13 @@ function simpletest_summarize_phpunit_result($results) {
  *
  * @return string
  *   Path to the PHPUnit XML file to use for the current $test_id.
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before 9.0.0. Use
+ *   \Drupal\Core\Test\PhpUnitTestRunner::xmlLogFilepath().
  */
 function simpletest_phpunit_xml_filepath($test_id) {
-  return \Drupal::service('file_system')->realpath('public://simpletest') . '/phpunit-' . $test_id . '.xml';
+  $runner = PhpUnitTestRunner::create(\Drupal::getContainer());
+  return $runner->xmlLogFilepath($test_id);
 }
 
 /**
@@ -313,65 +301,13 @@ function simpletest_phpunit_configuration_filepath() {
  *
  * @return string
  *   The results as returned by exec().
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before 9.0.0. Use
+ *   \Drupal\Core\Test\PhpUnitTestRunner::runCommand().
  */
 function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL) {
-  global $base_url;
-  // Setup an environment variable containing the database connection so that
-  // functional tests can connect to the database.
-  putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl());
-
-  // Setup an environment variable containing the base URL, if it is available.
-  // This allows functional tests to browse the site under test. When running
-  // tests via CLI, core/phpunit.xml.dist or core/scripts/run-tests.sh can set
-  // this variable.
-  if ($base_url) {
-    putenv('SIMPLETEST_BASE_URL=' . $base_url);
-    putenv('BROWSERTEST_OUTPUT_DIRECTORY=' . \Drupal::service('file_system')->realpath('public://simpletest'));
-  }
-  $phpunit_bin = simpletest_phpunit_command();
-
-  $command = [
-    $phpunit_bin,
-    '--log-junit',
-    escapeshellarg($phpunit_file),
-    '--printer',
-    escapeshellarg(SimpletestUiPrinter::class),
-  ];
-
-  // Optimized for running a single test.
-  if (count($unescaped_test_classnames) == 1) {
-    $class = new \ReflectionClass($unescaped_test_classnames[0]);
-    $command[] = escapeshellarg($class->getFileName());
-  }
-  else {
-    // Double escape namespaces so they'll work in a regexp.
-    $escaped_test_classnames = array_map(function($class) {
-      return addslashes($class);
-    }, $unescaped_test_classnames);
-
-    $filter_string = implode("|", $escaped_test_classnames);
-    $command = array_merge($command, [
-      '--filter',
-      escapeshellarg($filter_string),
-    ]);
-  }
-
-  // Need to change directories before running the command so that we can use
-  // relative paths in the configuration file's exclusions.
-  $old_cwd = getcwd();
-  chdir(\Drupal::root() . "/core");
-
-  // exec in a subshell so that the environment is isolated when running tests
-  // via the simpletest UI.
-  $ret = exec(join($command, " "), $output, $status);
-
-  chdir($old_cwd);
-  putenv('SIMPLETEST_DB=');
-  if ($base_url) {
-    putenv('SIMPLETEST_BASE_URL=');
-    putenv('BROWSERTEST_OUTPUT_DIRECTORY=');
-  }
-  return $ret;
+  $runner = PhpUnitTestRunner::create(\Drupal::getContainer());
+  return $runner->runCommand($unescaped_test_classnames, $phpunit_file, $status, $output);
 }
 
 /**
@@ -379,24 +315,13 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
  *
  * @return string
  *   The command that can be run through exec().
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before 9.0.0. Use
+ *   \Drupal\Core\Test\PhpUnitTestRunner::phpUnitCommand().
  */
 function simpletest_phpunit_command() {
-  // Load the actual autoloader being used and determine its filename using
-  // reflection. We can determine the vendor directory based on that filename.
-  $autoloader = require \Drupal::root() . '/autoload.php';
-  $reflector = new ReflectionClass($autoloader);
-  $vendor_dir = dirname(dirname($reflector->getFileName()));
-
-  // The file in Composer's bin dir is a *nix link, which does not work when
-  // extracted from a tarball and generally not on Windows.
-  $command = $vendor_dir . '/phpunit/phpunit/phpunit';
-  if (substr(PHP_OS, 0, 3) == 'WIN') {
-    // On Windows it is necessary to run the script using the PHP executable.
-    $php_executable_finder = new PhpExecutableFinder();
-    $php = $php_executable_finder->find();
-    $command = $php . ' -f ' . escapeshellarg($command) . ' --';
-  }
-  return $command;
+  $runner = PhpUnitTestRunner::create(\Drupal::getContainer());
+  return $runner->phpUnitCommand();
 }
 
 /**
@@ -776,18 +701,12 @@ function simpletest_mail_alter(&$message) {
  *   The results as array of rows in a format that can be inserted into
  *   {simpletest}. If the phpunit_xml_file does not have any contents then the
  *   function will return NULL.
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before 9.0.0. Use
+ *   \Drupal\Core\Test\JUnitConverter::xmlToRows().
  */
 function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) {
-  $contents = @file_get_contents($phpunit_xml_file);
-  if (!$contents) {
-    return;
-  }
-  $records = [];
-  $testcases = simpletest_phpunit_find_testcases(new SimpleXMLElement($contents));
-  foreach ($testcases as $testcase) {
-    $records[] = simpletest_phpunit_testcase_to_row($test_id, $testcase);
-  }
-  return $records;
+  return JUnitConverter::xmlToRows($test_id, $phpunit_xml_file);
 }
 
 /**
@@ -800,34 +719,12 @@ function simpletest_phpunit_xml_to_rows($test_id, $phpunit_xml_file) {
  *
  * @return array
  *   A list of all test cases.
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before 9.0.0. Use
+ *   \Drupal\Core\Test\JUnitConverter::findTestCases().
  */
 function simpletest_phpunit_find_testcases(\SimpleXMLElement $element, \SimpleXMLElement $parent = NULL) {
-  $testcases = [];
-
-  if (!isset($parent)) {
-    $parent = $element;
-  }
-
-  if ($element->getName() === 'testcase' && (int) $parent->attributes()->tests > 0) {
-    // Add the class attribute if the testcase does not have one. This is the
-    // case for tests using a data provider. The name of the parent testsuite
-    // will be in the format class::method.
-    if (!$element->attributes()->class) {
-      $name = explode('::', $parent->attributes()->name, 2);
-      $element->addAttribute('class', $name[0]);
-    }
-    $testcases[] = $element;
-  }
-  else {
-    foreach ($element as $child) {
-      $file = (string) $parent->attributes()->file;
-      if ($file && !$child->attributes()->file) {
-        $child->addAttribute('file', $file);
-      }
-      $testcases = array_merge($testcases, simpletest_phpunit_find_testcases($child, $element));
-    }
-  }
-  return $testcases;
+  return JUnitConverter::findTestcases($element, $parent);
 }
 
 /**
@@ -840,32 +737,10 @@ function simpletest_phpunit_find_testcases(\SimpleXMLElement $element, \SimpleXM
  *
  * @return array
  *   An array containing the {simpletest} result row.
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before 9.0.0. Use
+ *  \Drupal\Core\Test\JUnitConverter::testcaseToSimpletestRow().
  */
 function simpletest_phpunit_testcase_to_row($test_id, \SimpleXMLElement $testcase) {
-  $message = '';
-  $pass = TRUE;
-  if ($testcase->failure) {
-    $lines = explode("\n", $testcase->failure);
-    $message = $lines[2];
-    $pass = FALSE;
-  }
-  if ($testcase->error) {
-    $message = $testcase->error;
-    $pass = FALSE;
-  }
-
-  $attributes = $testcase->attributes();
-
-  $record = [
-    'test_id' => $test_id,
-    'test_class' => (string) $attributes->class,
-    'status' => $pass ? 'pass' : 'fail',
-    'message' => $message,
-    // @todo: Check on the proper values for this.
-    'message_group' => 'Other',
-    'function' => $attributes->class . '->' . $attributes->name . '()',
-    'line' => $attributes->line ?: 0,
-    'file' => $attributes->file,
-  ];
-  return $record;
+  return JUnitConverter::testcaseToSimpletestRow($test_id, $testcase);
 }
diff --git a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php
index 63fe1bb8a9..fec92c6043 100644
--- a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php
+++ b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php
@@ -4,14 +4,23 @@
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\File\FileSystemInterface;
+use Drupal\Core\Test\PhpUnitTestRunner;
 use PHPUnit\Framework\TestCase;
 
 /**
  * Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly.
  *
- * We don't extend Drupal\Tests\UnitTestCase here because its $root property is
+ * We don't extend \Drupal\Tests\UnitTestCase here because its $root property is
  * not static and we need it to be static here.
  *
+ * The file simpletest_phpunit_run_command_test.php contains the test class
+ * \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTestWillDie which
+ * can be made to exit with result code 2. It lives in a file which won't be
+ * autoloaded, so that it won't fail test runs.
+ *
+ * Here, we run SimpletestPhpunitRunCommandTestWillDie, make it die, and see
+ * what happens.
+ *
  * @group simpletest
  *
  * @runTestsInSeparateProcesses
@@ -25,6 +34,13 @@ class SimpletestPhpunitRunCommandTest extends TestCase {
    */
   protected static $root;
 
+  /**
+   * A fixture container.
+   *
+   * @var \Symfony\Component\DependencyInjection\ContainerInterface
+   */
+  protected $fixtureContainer;
+
   /**
    * {@inheritdoc}
    */
@@ -54,6 +70,7 @@ protected function setUp() {
     $file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir());
     $container->set('file_system', $file_system->reveal());
     \Drupal::setContainer($container);
+    $this->fixtureContainer = $container;
   }
 
   /**
@@ -80,6 +97,8 @@ public function provideStatusCodes() {
   /**
    * Test the round trip for PHPUnit execution status codes.
    *
+   * Also tests backwards-compatibility of PhpUnitTestRunner::runTests().
+   *
    * @covers ::simpletest_run_phpunit_tests
    *
    * @dataProvider provideStatusCodes
@@ -87,8 +106,17 @@ public function provideStatusCodes() {
   public function testSimpletestPhpUnitRunCommand($status, $label) {
     $test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
     putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
-    $ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
+
+    // Test against simpletest_run_phpunit_tests().
+    $bc_ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
+    $this->assertSame($bc_ret[0]['status'], $label);
+
+    // Test against PhpUnitTestRunner::runTests().
+    $runner = PhpUnitTestRunner::create($this->fixtureContainer);
+    $ret = $runner->runTests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
     $this->assertSame($ret[0]['status'], $label);
+
+    // Unset our environmental variable.
     putenv('SimpletestPhpunitRunCommandTestWillDie');
     unlink(simpletest_phpunit_xml_filepath($test_id));
   }
diff --git a/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php b/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php
new file mode 100644
index 0000000000..8668777070
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Drupal\Tests\Core\Test;
+
+use Drupal\Core\Test\PhpUnitTestRunner;
+use Drupal\Core\Test\TestStatus;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Test\PhpUnitTestRunner
+ * @group Test
+ *
+ * @see Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest
+ */
+class PhpUnitTestRunnerTest extends UnitTestCase {
+
+  /**
+   * Test an error in the test running phase.
+   *
+   * @covers ::runTests
+   */
+  public function testRunTestsError() {
+    $test_id = 23;
+    $log_path = 'test_log_path';
+
+    // Create a mock runner.
+    $runner = $this->getMockBuilder(PhpUnitTestRunner::class)
+      ->disableOriginalConstructor()
+      ->setMethods(['xmlLogFilepath', 'runCommand'])
+      ->getMock();
+
+    // Set some expectations for xmlLogFilepath().
+    $runner->expects($this->once())
+      ->method('xmlLogFilepath')
+      ->willReturn($log_path);
+
+    // We mark a failure by having runCommand() deliver a serious status code.
+    $runner->expects($this->once())
+      ->method('runCommand')
+      ->willReturnCallback(
+        function ($unescaped_test_classnames, $phpunit_file, &$status) {
+          $status = TestStatus::EXCEPTION;
+        }
+      );
+
+    // The runTests() method expects $status by reference, so we initialize it
+    // to some value we don't expect back.
+    $status = -1;
+    $results = $runner->runTests($test_id, ['SomeTest'], $status);
+
+    // Make sure our status code made the round trip.
+    $this->assertEquals(TestStatus::EXCEPTION, $status);
+
+    // A serious error in runCommand() should give us a fixed set of results.
+    $row = reset($results);
+    $fail_row = [
+      'test_id' => $test_id,
+      'test_class' => 'SomeTest',
+      'status' => TestStatus::label(TestStatus::EXCEPTION),
+      'message' => 'PHPunit Test failed to complete; Error: ',
+      'message_group' => 'Other',
+      'function' => 'SomeTest',
+      'line' => '0',
+      'file' => $log_path,
+    ];
+    $this->assertEquals($fail_row, $row);
+  }
+
+}
