diff --git a/core/lib/Drupal/Core/Test/Exception/MissingGroupException.php b/core/lib/Drupal/Core/Test/Exception/MissingGroupException.php
new file mode 100644
index 0000000000..448b4f5b2d
--- /dev/null
+++ b/core/lib/Drupal/Core/Test/Exception/MissingGroupException.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace Drupal\Core\Test\Exception;
+
+/**
+ * Exception thrown when a test class is missing an @group annotation.
+ *
+ * @see \Drupal\Core\Test\TestDiscovery::getTestClasses()
+ */
+class MissingGroupException extends \LogicException {
+}
diff --git a/core/lib/Drupal/Core/Test/TestDiscovery.php b/core/lib/Drupal/Core/Test/TestDiscovery.php
new file mode 100644
index 0000000000..e1510688d0
--- /dev/null
+++ b/core/lib/Drupal/Core/Test/TestDiscovery.php
@@ -0,0 +1,512 @@
+<?php
+
+namespace Drupal\Core\Test;
+
+use Doctrine\Common\Reflection\StaticReflectionParser;
+use Drupal\Component\Annotation\Reflection\MockFileFinder;
+use Drupal\Component\Utility\NestedArray;
+use Drupal\Core\Extension\ExtensionDiscovery;
+use Drupal\Core\Test\Exception\MissingGroupException;
+use PHPUnit_Util_Test;
+
+/**
+ * Discovers available tests.
+ */
+class TestDiscovery {
+
+  /**
+   * The class loader.
+   *
+   * @var \Composer\Autoload\ClassLoader
+   */
+  protected $classLoader;
+
+  /**
+   * Statically cached list of test classes.
+   *
+   * @var array
+   */
+  protected $testClasses;
+
+  /**
+   * Cached map of all test namespaces to respective directories.
+   *
+   * @var array
+   */
+  protected $testNamespaces;
+
+  /**
+   * Cached list of all available extension names, keyed by extension type.
+   *
+   * @var array
+   */
+  protected $availableExtensions;
+
+  /**
+   * The app root.
+   *
+   * @var string
+   */
+  protected $root;
+
+  /**
+   * Constructs a new test discovery.
+   *
+   * @param string $root
+   *   The app root.
+   * @param $class_loader
+   *   The class loader. Normally Composer's ClassLoader, as included by the
+   *   front controller, but may also be decorated; e.g.,
+   *   \Symfony\Component\ClassLoader\ApcClassLoader.
+   */
+  public function __construct($root, $class_loader) {
+    $this->root = $root;
+    $this->classLoader = $class_loader;
+  }
+
+  /**
+   * Registers test namespaces of all extensions and core test classes.
+   *
+   * @return array
+   *   An associative array whose keys are PSR-4 namespace prefixes and whose
+   *   values are directory names.
+   */
+  public function registerTestNamespaces() {
+    if (isset($this->testNamespaces)) {
+      return $this->testNamespaces;
+    }
+    $this->testNamespaces = [];
+
+    $existing = $this->classLoader->getPrefixesPsr4();
+
+    // Add PHPUnit test namespaces of Drupal core.
+    $this->testNamespaces['Drupal\\Tests\\'] = [$this->root . '/core/tests/Drupal/Tests'];
+    $this->testNamespaces['Drupal\\KernelTests\\'] = [$this->root . '/core/tests/Drupal/KernelTests'];
+    $this->testNamespaces['Drupal\\FunctionalTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalTests'];
+    $this->testNamespaces['Drupal\\FunctionalJavascriptTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalJavascriptTests'];
+
+    $this->availableExtensions = [];
+    foreach ($this->getExtensions() as $name => $extension) {
+      $this->availableExtensions[$extension->getType()][$name] = $name;
+
+      $base_path = $this->root . '/' . $extension->getPath();
+
+      // Add namespace of disabled/uninstalled extensions.
+      if (!isset($existing["Drupal\\$name\\"])) {
+        $this->classLoader->addPsr4("Drupal\\$name\\", "$base_path/src");
+      }
+      // Add Simpletest test namespace.
+      $this->testNamespaces["Drupal\\$name\\Tests\\"][] = "$base_path/src/Tests";
+
+      // Add PHPUnit test namespaces.
+      $this->testNamespaces["Drupal\\Tests\\$name\\Unit\\"][] = "$base_path/tests/src/Unit";
+      $this->testNamespaces["Drupal\\Tests\\$name\\Kernel\\"][] = "$base_path/tests/src/Kernel";
+      $this->testNamespaces["Drupal\\Tests\\$name\\Functional\\"][] = "$base_path/tests/src/Functional";
+      $this->testNamespaces["Drupal\\Tests\\$name\\FunctionalJavascript\\"][] = "$base_path/tests/src/FunctionalJavascript";
+
+      // Add discovery for traits which are shared between different test
+      // suites.
+      $this->testNamespaces["Drupal\\Tests\\$name\\Traits\\"][] = "$base_path/tests/src/Traits";
+    }
+
+    foreach ($this->testNamespaces as $prefix => $paths) {
+      $this->classLoader->addPsr4($prefix, $paths);
+    }
+
+    return $this->testNamespaces;
+  }
+
+  /**
+   * Discovers all available tests in all extensions.
+   *
+   * @param string $extension
+   *   (optional) The name of an extension to limit discovery to; e.g., 'node'.
+   * @param string[] $types
+   *   An array of included test types.
+   *
+   * @return array
+   *   An array of tests keyed by the the group name. If a test is annotated to
+   *   belong to multiple groups, it will appear under all group keys it belongs
+   *   to.
+   * @code
+   *     $groups['block'] => array(
+   *       'Drupal\Tests\block\Functional\BlockTest' => array(
+   *         'name' => 'Drupal\Tests\block\Functional\BlockTest',
+   *         'description' => 'Tests block UI CRUD functionality.',
+   *         'group' => 'block',
+   *         'groups' => ['block', 'group2', 'group3'],
+   *       ),
+   *     );
+   * @endcode
+   *
+   * @todo Remove singular grouping; retain list of groups in 'group' key.
+   * @see https://www.drupal.org/node/2296615
+   */
+  public function getTestClasses($extension = NULL, array $types = []) {
+    if (!isset($extension) && empty($types)) {
+      if (!empty($this->testClasses)) {
+        return $this->testClasses;
+      }
+    }
+    $list = [];
+
+    $classmap = $this->findAllClassFiles($extension);
+
+    // Prevent expensive class loader lookups for each reflected test class by
+    // registering the complete classmap of test classes to the class loader.
+    // This also ensures that test classes are loaded from the discovered
+    // pathnames; a namespace/classname mismatch will throw an exception.
+    $this->classLoader->addClassMap($classmap);
+
+    foreach ($classmap as $classname => $pathname) {
+      $finder = MockFileFinder::create($pathname);
+      $parser = new StaticReflectionParser($classname, $finder, TRUE);
+      try {
+        $info = static::getTestInfo($classname, $parser->getDocComment());
+      }
+      catch (MissingGroupException $e) {
+        // If the class name ends in Test and is not a migrate table dump.
+        if (preg_match('/Test$/', $classname) && strpos($classname, 'migrate_drupal\Tests\Table') === FALSE) {
+          throw $e;
+        }
+        // If the class is @group annotation just skip it. Most likely it is an
+        // abstract class, trait or test fixture.
+        continue;
+      }
+      // Skip this test class if it is a Simpletest-based test and requires
+      // unavailable modules. TestDiscovery should not filter out module
+      // requirements for PHPUnit-based test classes.
+      // @todo Move this behavior to \Drupal\simpletest\TestBase so tests can be
+      //       marked as skipped, instead.
+      // @see https://www.drupal.org/node/1273478
+      if ($info['type'] == 'Simpletest') {
+        if (!empty($info['requires']['module'])) {
+          if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
+            continue;
+          }
+        }
+      }
+
+      foreach ($info['groups'] as $group) {
+        $list[$group][$classname] = $info;
+      }
+    }
+
+    // Sort the groups and tests within the groups by name.
+    uksort($list, 'strnatcasecmp');
+    foreach ($list as &$tests) {
+      uksort($tests, 'strnatcasecmp');
+    }
+
+    $this->alterHook($list);
+
+    if (!isset($extension) && empty($types)) {
+      $this->testClasses = $list;
+    }
+
+    if ($types) {
+      $list = NestedArray::filter($list, function ($element) use ($types) {
+        return !(is_array($element) && isset($element['type']) && !in_array($element['type'], $types));
+      });
+    }
+
+    return $list;
+  }
+
+  /**
+   * Allow subclasses to invoke module hooks on the test list.
+   *
+   * This method can manipulate the test list.
+   *
+   * @param array $test_list
+   *   An array of tests keyed by the the group name.
+   *
+   * @todo Remove this when the simpletest module no longer needs to fire its
+   *   hook.
+   *
+   * @see hook_simpletest_alter()
+   * @see https://www.drupal.org/project/drupal/issues/2866082
+   * @see https://www.drupal.org/node/2939892
+   * @see https://www.drupal.org/node/2949692
+   */
+  protected function alterHook(&$test_list) {
+    return;
+  }
+
+  /**
+   * Discovers all class files in all available extensions.
+   *
+   * @param string $extension
+   *   (optional) The name of an extension to limit discovery to; e.g., 'node'.
+   *
+   * @return array
+   *   A classmap containing all discovered class files; i.e., a map of
+   *   fully-qualified classnames to pathnames.
+   */
+  public function findAllClassFiles($extension = NULL) {
+    $classmap = [];
+    $namespaces = $this->registerTestNamespaces();
+    if (isset($extension)) {
+      // Include tests in the \Drupal\Tests\{$extension} namespace.
+      $pattern = "/Drupal\\\(Tests\\\)?$extension\\\/";
+      $namespaces = array_intersect_key($namespaces, array_flip(preg_grep($pattern, array_keys($namespaces))));
+    }
+    foreach ($namespaces as $namespace => $paths) {
+      foreach ($paths as $path) {
+        if (!is_dir($path)) {
+          continue;
+        }
+        $classmap += static::scanDirectory($namespace, $path);
+      }
+    }
+    return $classmap;
+  }
+
+  /**
+   * Scans a given directory for class files.
+   *
+   * @param string $namespace_prefix
+   *   The namespace prefix to use for discovered classes. Must contain a
+   *   trailing namespace separator (backslash).
+   *   For example: 'Drupal\\node\\Tests\\'
+   * @param string $path
+   *   The directory path to scan.
+   *   For example: '/path/to/drupal/core/modules/node/tests/src'
+   *
+   * @return array
+   *   An associative array whose keys are fully-qualified class names and whose
+   *   values are corresponding filesystem pathnames.
+   *
+   * @throws \InvalidArgumentException
+   *   If $namespace_prefix does not end in a namespace separator (backslash).
+   *
+   * @todo Limit to '*Test.php' files (~10% less files to reflect/introspect).
+   * @see https://www.drupal.org/node/2296635
+   */
+  public static function scanDirectory($namespace_prefix, $path) {
+    if (substr($namespace_prefix, -1) !== '\\') {
+      throw new \InvalidArgumentException("Namespace prefix for $path must contain a trailing namespace separator.");
+    }
+    $flags = \FilesystemIterator::UNIX_PATHS;
+    $flags |= \FilesystemIterator::SKIP_DOTS;
+    $flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
+    $flags |= \FilesystemIterator::CURRENT_AS_SELF;
+    $flags |= \FilesystemIterator::KEY_AS_FILENAME;
+
+    $iterator = new \RecursiveDirectoryIterator($path, $flags);
+    $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $file_name, $iterator) {
+      if ($iterator->hasChildren()) {
+        return TRUE;
+      }
+      // We don't want to discover abstract TestBase classes, traits or
+      // interfaces. They can be deprecated and will call @trigger_error()
+      // during discovery.
+      return
+        substr($file_name, -4) === '.php' &&
+        substr($file_name, -12) !== 'TestBase.php' &&
+        substr($file_name, -9) !== 'Trait.php' &&
+        substr($file_name, -13) !== 'Interface.php';
+    });
+    $files = new \RecursiveIteratorIterator($filter);
+    $classes = [];
+    foreach ($files as $fileinfo) {
+      $class = $namespace_prefix;
+      if ('' !== $subpath = $fileinfo->getSubPath()) {
+        $class .= strtr($subpath, '/', '\\') . '\\';
+      }
+      $class .= $fileinfo->getBasename('.php');
+      $classes[$class] = $fileinfo->getPathname();
+    }
+    return $classes;
+  }
+
+  /**
+   * Retrieves information about a test class for UI purposes.
+   *
+   * @param string $classname
+   *   The test classname.
+   * @param string $doc_comment
+   *   (optional) The class PHPDoc comment. If not passed in reflection will be
+   *   used but this is very expensive when parsing all the test classes.
+   *
+   * @return array
+   *   An associative array containing:
+   *   - name: The test class name.
+   *   - description: The test (PHPDoc) summary.
+   *   - group: The test's first @group (parsed from PHPDoc annotations).
+   *   - groups: All of the test's @group annotations, as an array (parsed from
+   *     PHPDoc annotations).
+   *   - requires: An associative array containing test requirements parsed from
+   *     PHPDoc annotations:
+   *     - module: List of Drupal module extension names the test depends on.
+   *
+   * @throws \Drupal\simpletest\Exception\MissingGroupException
+   *   If the class does not have a @group annotation.
+   */
+  public static function getTestInfo($classname, $doc_comment = NULL) {
+    if ($doc_comment === NULL) {
+      $reflection = new \ReflectionClass($classname);
+      $doc_comment = $reflection->getDocComment();
+    }
+    $info = [
+      'name' => $classname,
+    ];
+    $annotations = [];
+    // Look for annotations, allow an arbitrary amount of spaces before the
+    // * but nothing else.
+    preg_match_all('/^[ ]*\* \@([^\s]*) (.*$)/m', $doc_comment, $matches);
+    if (isset($matches[1])) {
+      foreach ($matches[1] as $key => $annotation) {
+        // For historical reasons, there is a single-value 'group' result key
+        // and a 'groups' key as an array.
+        if ($annotation === 'group') {
+          $annotations['groups'][] = $matches[2][$key];
+        }
+        if (!empty($annotations[$annotation])) {
+          // Only @group is allowed to have more than one annotation, in the
+          // 'groups' key. Other annotations only have one value per key.
+          continue;
+        }
+        $annotations[$annotation] = $matches[2][$key];
+      }
+    }
+
+    if (empty($annotations['group'])) {
+      // Concrete tests must have a group.
+      throw new MissingGroupException(sprintf('Missing @group annotation in %s', $classname));
+    }
+    $info['group'] = $annotations['group'];
+    $info['groups'] = $annotations['groups'];
+
+    // Sort out PHPUnit-runnable tests by type.
+    if ($testsuite = static::getPhpunitTestSuite($classname)) {
+      $info['type'] = 'PHPUnit-' . $testsuite;
+    }
+    else {
+      $info['type'] = 'Simpletest';
+    }
+
+    if (!empty($annotations['coversDefaultClass'])) {
+      $info['description'] = 'Tests ' . $annotations['coversDefaultClass'] . '.';
+    }
+    else {
+      $info['description'] = static::parseTestClassSummary($doc_comment);
+    }
+    if (isset($annotations['dependencies'])) {
+      $info['requires']['module'] = array_map('trim', explode(',', $annotations['dependencies']));
+    }
+
+    return $info;
+  }
+
+  /**
+   * Parses the phpDoc summary line of a test class.
+   *
+   * @param string $doc_comment
+   *
+   * @return string
+   *   The parsed phpDoc summary line. An empty string is returned if no summary
+   *   line can be parsed.
+   */
+  public static function parseTestClassSummary($doc_comment) {
+    // Normalize line endings.
+    $doc_comment = preg_replace('/\r\n|\r/', '\n', $doc_comment);
+    // Strip leading and trailing doc block lines.
+    $doc_comment = substr($doc_comment, 4, -4);
+
+    $lines = explode("\n", $doc_comment);
+    $summary = [];
+    // Add every line to the summary until the first empty line or annotation
+    // is found.
+    foreach ($lines as $line) {
+      if (preg_match('/^[ ]*\*$/', $line) || preg_match('/^[ ]*\* \@/', $line)) {
+        break;
+      }
+      $summary[] = trim($line, ' *');
+    }
+    return implode(' ', $summary);
+  }
+
+  /**
+   * Parses annotations in the phpDoc of a test class.
+   *
+   * @param \ReflectionClass $class
+   *   The reflected test class.
+   *
+   * @return array
+   *   An associative array that contains all annotations on the test class;
+   *   typically including:
+   *   - group: A list of @group values.
+   *   - requires: An associative array of @requires values; e.g.:
+   *     - module: A list of Drupal module dependencies that are required to
+   *       exist.
+   *
+   * @see PHPUnit_Util_Test::parseTestMethodAnnotations()
+   * @see http://phpunit.de/manual/current/en/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests.skipping-tests-using-requires
+   */
+  public static function parseTestClassAnnotations(\ReflectionClass $class) {
+    $annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($class->getName())['class'];
+
+    // @todo Enhance PHPUnit upstream to allow for custom @requires identifiers.
+    // @see PHPUnit_Util_Test::getRequirements()
+    // @todo Add support for 'PHP', 'OS', 'function', 'extension'.
+    // @see https://www.drupal.org/node/1273478
+    if (isset($annotations['requires'])) {
+      foreach ($annotations['requires'] as $i => $value) {
+        list($type, $value) = explode(' ', $value, 2);
+        if ($type === 'module') {
+          $annotations['requires']['module'][$value] = $value;
+          unset($annotations['requires'][$i]);
+        }
+      }
+    }
+    return $annotations;
+  }
+
+  /**
+   * Determines the phpunit testsuite for a given classname.
+   *
+   * @param string $classname
+   *   The test classname.
+   *
+   * @return string|false
+   *   The testsuite name or FALSE if its not a phpunit test.
+   */
+  public static function getPhpunitTestSuite($classname) {
+    if (preg_match('/Drupal\\\\Tests\\\\Core\\\\(\w+)/', $classname, $matches)) {
+      return 'Unit';
+    }
+    if (preg_match('/Drupal\\\\Tests\\\\Component\\\\(\w+)/', $classname, $matches)) {
+      return 'Unit';
+    }
+    // Module tests.
+    if (preg_match('/Drupal\\\\Tests\\\\(\w+)\\\\(\w+)/', $classname, $matches)) {
+      return $matches[2];
+    }
+    // Core tests.
+    elseif (preg_match('/Drupal\\\\(\w*)Tests\\\\/', $classname, $matches)) {
+      if ($matches[1] == '') {
+        return 'Unit';
+      }
+      return $matches[1];
+    }
+    return FALSE;
+  }
+
+  /**
+   * Returns all available extensions.
+   *
+   * @return \Drupal\Core\Extension\Extension[]
+   *   An array of Extension objects, keyed by extension name.
+   */
+  protected function getExtensions() {
+    $listing = new ExtensionDiscovery($this->root);
+    // Ensure that tests in all profiles are discovered.
+    $listing->setProfileDirectories([]);
+    $extensions = $listing->scan('module', TRUE);
+    $extensions += $listing->scan('profile', TRUE);
+    $extensions += $listing->scan('theme', TRUE);
+    return $extensions;
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Test/TestRunnerKernel.php b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
index b615ce356f..972c9572ff 100644
--- a/core/lib/Drupal/Core/Test/TestRunnerKernel.php
+++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
@@ -5,6 +5,7 @@
 use Drupal\Core\DrupalKernel;
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Site\Settings;
+use Drupal\Core\Test\TestDiscovery;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index 92226508a8..80905a704e 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -12,7 +12,7 @@
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\simpletest\TestBase;
 use Drupal\Core\Test\TestDatabase;
-use Drupal\simpletest\TestDiscovery;
+use Drupal\Core\Test\TestDiscovery;
 use Drupal\Tests\Listeners\SimpletestUiPrinter;
 use PHPUnit\Framework\TestCase;
 use Symfony\Component\Process\PhpExecutableFinder;
diff --git a/core/modules/simpletest/src/Exception/MissingGroupException.php b/core/modules/simpletest/src/Exception/MissingGroupException.php
index 85a0696ca1..613d585ddb 100644
--- a/core/modules/simpletest/src/Exception/MissingGroupException.php
+++ b/core/modules/simpletest/src/Exception/MissingGroupException.php
@@ -2,8 +2,19 @@
 
 namespace Drupal\simpletest\Exception;
 
+@trigger_error('Deprecated in Drupal 8.7.x for removal before Drupal 9.0.0 release. Use \Drupal\Core\Test\Exception\MissingGroupException instead. https://www.drupal.org/node/2949692', E_USER_DEPRECATED);
+
+use Drupal\Core\Test\Exception\MissingGroupException as CoreMissingGroupException;
+
 /**
  * Exception thrown when a simpletest class is missing an @group annotation.
+ *
+ * @deprecated in Drupal 8.7.x for removal before Drupal 9.0.0 release. Use
+ *   \Drupal\Core\Test\Exception\MissingGroupException instead.
+ *
+ * @see \Drupal\Core\Test\Exception\MissingGroupException
+ *
+ * @see https://www.drupal.org/node/2949692
  */
-class MissingGroupException extends \LogicException {
+class MissingGroupException extends CoreMissingGroupException {
 }
diff --git a/core/modules/simpletest/src/Form/SimpletestResultsForm.php b/core/modules/simpletest/src/Form/SimpletestResultsForm.php
index a2241571eb..e278ce621b 100644
--- a/core/modules/simpletest/src/Form/SimpletestResultsForm.php
+++ b/core/modules/simpletest/src/Form/SimpletestResultsForm.php
@@ -7,7 +7,7 @@
 use Drupal\Core\Form\FormState;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Url;
-use Drupal\simpletest\TestDiscovery;
+use Drupal\Core\Test\TestDiscovery;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 
diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php
index a9cbe15db7..6c0321a686 100644
--- a/core/modules/simpletest/src/TestDiscovery.php
+++ b/core/modules/simpletest/src/TestDiscovery.php
@@ -2,53 +2,16 @@
 
 namespace Drupal\simpletest;
 
-use Doctrine\Common\Reflection\StaticReflectionParser;
-use Drupal\Component\Annotation\Reflection\MockFileFinder;
-use Drupal\Component\Utility\NestedArray;
-use Drupal\Core\Extension\ExtensionDiscovery;
 use Drupal\Core\Extension\ModuleHandlerInterface;
-use Drupal\simpletest\Exception\MissingGroupException;
-use PHPUnit_Util_Test;
+use Drupal\Core\Test\TestDiscovery as CoreTestDiscovery;
 
 /**
  * Discovers available tests.
+ *
+ * This class provides backwards compatibility for code which uses the
+ * 'test_discovery' service.
  */
-class TestDiscovery {
-
-  /**
-   * The class loader.
-   *
-   * @var \Composer\Autoload\ClassLoader
-   */
-  protected $classLoader;
-
-  /**
-   * Statically cached list of test classes.
-   *
-   * @var array
-   */
-  protected $testClasses;
-
-  /**
-   * Cached map of all test namespaces to respective directories.
-   *
-   * @var array
-   */
-  protected $testNamespaces;
-
-  /**
-   * Cached list of all available extension names, keyed by extension type.
-   *
-   * @var array
-   */
-  protected $availableExtensions;
-
-  /**
-   * The app root.
-   *
-   * @var string
-   */
-  protected $root;
+class TestDiscovery extends CoreTestDiscovery {
 
   /**
    * The module handler.
@@ -70,434 +33,17 @@ class TestDiscovery {
    *   The module handler.
    */
   public function __construct($root, $class_loader, ModuleHandlerInterface $module_handler) {
-    $this->root = $root;
-    $this->classLoader = $class_loader;
     $this->moduleHandler = $module_handler;
+    parent::__construct($root, $class_loader);
   }
 
   /**
-   * Registers test namespaces of all extensions and core test classes.
-   *
-   * @return array
-   *   An associative array whose keys are PSR-4 namespace prefixes and whose
-   *   values are directory names.
+   * {@inheritdoc}
    */
-  public function registerTestNamespaces() {
-    if (isset($this->testNamespaces)) {
-      return $this->testNamespaces;
-    }
-    $this->testNamespaces = [];
-
-    $existing = $this->classLoader->getPrefixesPsr4();
-
-    // Add PHPUnit test namespaces of Drupal core.
-    $this->testNamespaces['Drupal\\Tests\\'] = [$this->root . '/core/tests/Drupal/Tests'];
-    $this->testNamespaces['Drupal\\KernelTests\\'] = [$this->root . '/core/tests/Drupal/KernelTests'];
-    $this->testNamespaces['Drupal\\FunctionalTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalTests'];
-    $this->testNamespaces['Drupal\\FunctionalJavascriptTests\\'] = [$this->root . '/core/tests/Drupal/FunctionalJavascriptTests'];
-
-    $this->availableExtensions = [];
-    foreach ($this->getExtensions() as $name => $extension) {
-      $this->availableExtensions[$extension->getType()][$name] = $name;
-
-      $base_path = $this->root . '/' . $extension->getPath();
-
-      // Add namespace of disabled/uninstalled extensions.
-      if (!isset($existing["Drupal\\$name\\"])) {
-        $this->classLoader->addPsr4("Drupal\\$name\\", "$base_path/src");
-      }
-      // Add Simpletest test namespace.
-      $this->testNamespaces["Drupal\\$name\\Tests\\"][] = "$base_path/src/Tests";
-
-      // Add PHPUnit test namespaces.
-      $this->testNamespaces["Drupal\\Tests\\$name\\Unit\\"][] = "$base_path/tests/src/Unit";
-      $this->testNamespaces["Drupal\\Tests\\$name\\Kernel\\"][] = "$base_path/tests/src/Kernel";
-      $this->testNamespaces["Drupal\\Tests\\$name\\Functional\\"][] = "$base_path/tests/src/Functional";
-      $this->testNamespaces["Drupal\\Tests\\$name\\FunctionalJavascript\\"][] = "$base_path/tests/src/FunctionalJavascript";
-
-      // Add discovery for traits which are shared between different test
-      // suites.
-      $this->testNamespaces["Drupal\\Tests\\$name\\Traits\\"][] = "$base_path/tests/src/Traits";
-    }
-
-    foreach ($this->testNamespaces as $prefix => $paths) {
-      $this->classLoader->addPsr4($prefix, $paths);
-    }
-
-    return $this->testNamespaces;
-  }
-
-  /**
-   * Discovers all available tests in all extensions.
-   *
-   * @param string $extension
-   *   (optional) The name of an extension to limit discovery to; e.g., 'node'.
-   * @param string[] $types
-   *   An array of included test types.
-   *
-   * @return array
-   *   An array of tests keyed by the the group name. If a test is annotated to
-   *   belong to multiple groups, it will appear under all group keys it belongs
-   *   to.
-   * @code
-   *     $groups['block'] => array(
-   *       'Drupal\Tests\block\Functional\BlockTest' => array(
-   *         'name' => 'Drupal\Tests\block\Functional\BlockTest',
-   *         'description' => 'Tests block UI CRUD functionality.',
-   *         'group' => 'block',
-   *         'groups' => ['block', 'group2', 'group3'],
-   *       ),
-   *     );
-   * @endcode
-   *
-   * @todo Remove singular grouping; retain list of groups in 'group' key.
-   * @see https://www.drupal.org/node/2296615
-   */
-  public function getTestClasses($extension = NULL, array $types = []) {
-    if (!isset($extension) && empty($types)) {
-      if (!empty($this->testClasses)) {
-        return $this->testClasses;
-      }
-    }
-    $list = [];
-
-    $classmap = $this->findAllClassFiles($extension);
-
-    // Prevent expensive class loader lookups for each reflected test class by
-    // registering the complete classmap of test classes to the class loader.
-    // This also ensures that test classes are loaded from the discovered
-    // pathnames; a namespace/classname mismatch will throw an exception.
-    $this->classLoader->addClassMap($classmap);
-
-    foreach ($classmap as $classname => $pathname) {
-      $finder = MockFileFinder::create($pathname);
-      $parser = new StaticReflectionParser($classname, $finder, TRUE);
-      try {
-        $info = static::getTestInfo($classname, $parser->getDocComment());
-      }
-      catch (MissingGroupException $e) {
-        // If the class name ends in Test and is not a migrate table dump.
-        if (preg_match('/Test$/', $classname) && strpos($classname, 'migrate_drupal\Tests\Table') === FALSE) {
-          throw $e;
-        }
-        // If the class is @group annotation just skip it. Most likely it is an
-        // abstract class, trait or test fixture.
-        continue;
-      }
-      // Skip this test class if it is a Simpletest-based test and requires
-      // unavailable modules. TestDiscovery should not filter out module
-      // requirements for PHPUnit-based test classes.
-      // @todo Move this behavior to \Drupal\simpletest\TestBase so tests can be
-      //       marked as skipped, instead.
-      // @see https://www.drupal.org/node/1273478
-      if ($info['type'] == 'Simpletest') {
-        if (!empty($info['requires']['module'])) {
-          if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
-            continue;
-          }
-        }
-      }
-
-      foreach ($info['groups'] as $group) {
-        $list[$group][$classname] = $info;
-      }
-    }
-
-    // Sort the groups and tests within the groups by name.
-    uksort($list, 'strnatcasecmp');
-    foreach ($list as &$tests) {
-      uksort($tests, 'strnatcasecmp');
-    }
-
-    // Allow modules extending core tests to disable originals.
+  protected function alterHook(&$test_list) {
+    // @see hook_simpletest_alter()
+    // @see https://www.drupal.org/node/2939892
     $this->moduleHandler->alterDeprecated('Convert your test to a PHPUnit-based one and implement test listeners. See: https://www.drupal.org/node/2939892', 'simpletest', $list);
-
-    if (!isset($extension) && empty($types)) {
-      $this->testClasses = $list;
-    }
-
-    if ($types) {
-      $list = NestedArray::filter($list, function ($element) use ($types) {
-        return !(is_array($element) && isset($element['type']) && !in_array($element['type'], $types));
-      });
-    }
-
-    return $list;
-  }
-
-  /**
-   * Discovers all class files in all available extensions.
-   *
-   * @param string $extension
-   *   (optional) The name of an extension to limit discovery to; e.g., 'node'.
-   *
-   * @return array
-   *   A classmap containing all discovered class files; i.e., a map of
-   *   fully-qualified classnames to pathnames.
-   */
-  public function findAllClassFiles($extension = NULL) {
-    $classmap = [];
-    $namespaces = $this->registerTestNamespaces();
-    if (isset($extension)) {
-      // Include tests in the \Drupal\Tests\{$extension} namespace.
-      $pattern = "/Drupal\\\(Tests\\\)?$extension\\\/";
-      $namespaces = array_intersect_key($namespaces, array_flip(preg_grep($pattern, array_keys($namespaces))));
-    }
-    foreach ($namespaces as $namespace => $paths) {
-      foreach ($paths as $path) {
-        if (!is_dir($path)) {
-          continue;
-        }
-        $classmap += static::scanDirectory($namespace, $path);
-      }
-    }
-    return $classmap;
-  }
-
-  /**
-   * Scans a given directory for class files.
-   *
-   * @param string $namespace_prefix
-   *   The namespace prefix to use for discovered classes. Must contain a
-   *   trailing namespace separator (backslash).
-   *   For example: 'Drupal\\node\\Tests\\'
-   * @param string $path
-   *   The directory path to scan.
-   *   For example: '/path/to/drupal/core/modules/node/tests/src'
-   *
-   * @return array
-   *   An associative array whose keys are fully-qualified class names and whose
-   *   values are corresponding filesystem pathnames.
-   *
-   * @throws \InvalidArgumentException
-   *   If $namespace_prefix does not end in a namespace separator (backslash).
-   *
-   * @todo Limit to '*Test.php' files (~10% less files to reflect/introspect).
-   * @see https://www.drupal.org/node/2296635
-   */
-  public static function scanDirectory($namespace_prefix, $path) {
-    if (substr($namespace_prefix, -1) !== '\\') {
-      throw new \InvalidArgumentException("Namespace prefix for $path must contain a trailing namespace separator.");
-    }
-    $flags = \FilesystemIterator::UNIX_PATHS;
-    $flags |= \FilesystemIterator::SKIP_DOTS;
-    $flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
-    $flags |= \FilesystemIterator::CURRENT_AS_SELF;
-    $flags |= \FilesystemIterator::KEY_AS_FILENAME;
-
-    $iterator = new \RecursiveDirectoryIterator($path, $flags);
-    $filter = new \RecursiveCallbackFilterIterator($iterator, function ($current, $file_name, $iterator) {
-      if ($iterator->hasChildren()) {
-        return TRUE;
-      }
-      // We don't want to discover abstract TestBase classes, traits or
-      // interfaces. They can be deprecated and will call @trigger_error()
-      // during discovery.
-      return substr($file_name, -4) === '.php' &&
-        substr($file_name, -12) !== 'TestBase.php' &&
-        substr($file_name, -9) !== 'Trait.php' &&
-        substr($file_name, -13) !== 'Interface.php';
-    });
-    $files = new \RecursiveIteratorIterator($filter);
-    $classes = [];
-    foreach ($files as $fileinfo) {
-      $class = $namespace_prefix;
-      if ('' !== $subpath = $fileinfo->getSubPath()) {
-        $class .= strtr($subpath, '/', '\\') . '\\';
-      }
-      $class .= $fileinfo->getBasename('.php');
-      $classes[$class] = $fileinfo->getPathname();
-    }
-    return $classes;
-  }
-
-  /**
-   * Retrieves information about a test class for UI purposes.
-   *
-   * @param string $classname
-   *   The test classname.
-   * @param string $doc_comment
-   *   (optional) The class PHPDoc comment. If not passed in reflection will be
-   *   used but this is very expensive when parsing all the test classes.
-   *
-   * @return array
-   *   An associative array containing:
-   *   - name: The test class name.
-   *   - description: The test (PHPDoc) summary.
-   *   - group: The test's first @group (parsed from PHPDoc annotations).
-   *   - groups: All of the test's @group annotations, as an array (parsed from
-   *     PHPDoc annotations).
-   *   - requires: An associative array containing test requirements parsed from
-   *     PHPDoc annotations:
-   *     - module: List of Drupal module extension names the test depends on.
-   *
-   * @throws \Drupal\simpletest\Exception\MissingGroupException
-   *   If the class does not have a @group annotation.
-   */
-  public static function getTestInfo($classname, $doc_comment = NULL) {
-    if ($doc_comment === NULL) {
-      $reflection = new \ReflectionClass($classname);
-      $doc_comment = $reflection->getDocComment();
-    }
-    $info = [
-      'name' => $classname,
-    ];
-    $annotations = [];
-    // Look for annotations, allow an arbitrary amount of spaces before the
-    // * but nothing else.
-    preg_match_all('/^[ ]*\* \@([^\s]*) (.*$)/m', $doc_comment, $matches);
-    if (isset($matches[1])) {
-      foreach ($matches[1] as $key => $annotation) {
-        // For historical reasons, there is a single-value 'group' result key
-        // and a 'groups' key as an array.
-        if ($annotation === 'group') {
-          $annotations['groups'][] = $matches[2][$key];
-        }
-        if (!empty($annotations[$annotation])) {
-          // Only @group is allowed to have more than one annotation, in the
-          // 'groups' key. Other annotations only have one value per key.
-          continue;
-        }
-        $annotations[$annotation] = $matches[2][$key];
-      }
-    }
-
-    if (empty($annotations['group'])) {
-      // Concrete tests must have a group.
-      throw new MissingGroupException(sprintf('Missing @group annotation in %s', $classname));
-    }
-    $info['group'] = $annotations['group'];
-    $info['groups'] = $annotations['groups'];
-
-    // Sort out PHPUnit-runnable tests by type.
-    if ($testsuite = static::getPhpunitTestSuite($classname)) {
-      $info['type'] = 'PHPUnit-' . $testsuite;
-    }
-    else {
-      $info['type'] = 'Simpletest';
-    }
-
-    if (!empty($annotations['coversDefaultClass'])) {
-      $info['description'] = 'Tests ' . $annotations['coversDefaultClass'] . '.';
-    }
-    else {
-      $info['description'] = static::parseTestClassSummary($doc_comment);
-    }
-    if (isset($annotations['dependencies'])) {
-      $info['requires']['module'] = array_map('trim', explode(',', $annotations['dependencies']));
-    }
-
-    return $info;
-  }
-
-  /**
-   * Parses the phpDoc summary line of a test class.
-   *
-   * @param string $doc_comment
-   *
-   * @return string
-   *   The parsed phpDoc summary line. An empty string is returned if no summary
-   *   line can be parsed.
-   */
-  public static function parseTestClassSummary($doc_comment) {
-    // Normalize line endings.
-    $doc_comment = preg_replace('/\r\n|\r/', '\n', $doc_comment);
-    // Strip leading and trailing doc block lines.
-    $doc_comment = substr($doc_comment, 4, -4);
-
-    $lines = explode("\n", $doc_comment);
-    $summary = [];
-    // Add every line to the summary until the first empty line or annotation
-    // is found.
-    foreach ($lines as $line) {
-      if (preg_match('/^[ ]*\*$/', $line) || preg_match('/^[ ]*\* \@/', $line)) {
-        break;
-      }
-      $summary[] = trim($line, ' *');
-    }
-    return implode(' ', $summary);
-  }
-
-  /**
-   * Parses annotations in the phpDoc of a test class.
-   *
-   * @param \ReflectionClass $class
-   *   The reflected test class.
-   *
-   * @return array
-   *   An associative array that contains all annotations on the test class;
-   *   typically including:
-   *   - group: A list of @group values.
-   *   - requires: An associative array of @requires values; e.g.:
-   *     - module: A list of Drupal module dependencies that are required to
-   *       exist.
-   *
-   * @see PHPUnit_Util_Test::parseTestMethodAnnotations()
-   * @see http://phpunit.de/manual/current/en/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests.skipping-tests-using-requires
-   */
-  public static function parseTestClassAnnotations(\ReflectionClass $class) {
-    $annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($class->getName())['class'];
-
-    // @todo Enhance PHPUnit upstream to allow for custom @requires identifiers.
-    // @see PHPUnit_Util_Test::getRequirements()
-    // @todo Add support for 'PHP', 'OS', 'function', 'extension'.
-    // @see https://www.drupal.org/node/1273478
-    if (isset($annotations['requires'])) {
-      foreach ($annotations['requires'] as $i => $value) {
-        list($type, $value) = explode(' ', $value, 2);
-        if ($type === 'module') {
-          $annotations['requires']['module'][$value] = $value;
-          unset($annotations['requires'][$i]);
-        }
-      }
-    }
-    return $annotations;
-  }
-
-  /**
-   * Determines the phpunit testsuite for a given classname.
-   *
-   * @param string $classname
-   *   The test classname.
-   *
-   * @return string|false
-   *   The testsuite name or FALSE if its not a phpunit test.
-   */
-  public static function getPhpunitTestSuite($classname) {
-    if (preg_match('/Drupal\\\\Tests\\\\Core\\\\(\w+)/', $classname, $matches)) {
-      return 'Unit';
-    }
-    if (preg_match('/Drupal\\\\Tests\\\\Component\\\\(\w+)/', $classname, $matches)) {
-      return 'Unit';
-    }
-    // Module tests.
-    if (preg_match('/Drupal\\\\Tests\\\\(\w+)\\\\(\w+)/', $classname, $matches)) {
-      return $matches[2];
-    }
-    // Core tests.
-    elseif (preg_match('/Drupal\\\\(\w*)Tests\\\\/', $classname, $matches)) {
-      if ($matches[1] == '') {
-        return 'Unit';
-      }
-      return $matches[1];
-    }
-    return FALSE;
-  }
-
-  /**
-   * Returns all available extensions.
-   *
-   * @return \Drupal\Core\Extension\Extension[]
-   *   An array of Extension objects, keyed by extension name.
-   */
-  protected function getExtensions() {
-    $listing = new ExtensionDiscovery($this->root);
-    // Ensure that tests in all profiles are discovered.
-    $listing->setProfileDirectories([]);
-    $extensions = $listing->scan('module', TRUE);
-    $extensions += $listing->scan('profile', TRUE);
-    $extensions += $listing->scan('theme', TRUE);
-    return $extensions;
   }
 
 }
diff --git a/core/modules/simpletest/tests/src/Kernel/TestDiscoveryDeprecationTest.php b/core/modules/simpletest/tests/src/Kernel/TestDiscoveryDeprecationTest.php
index 6d4f44888a..3a1eb0a23a 100644
--- a/core/modules/simpletest/tests/src/Kernel/TestDiscoveryDeprecationTest.php
+++ b/core/modules/simpletest/tests/src/Kernel/TestDiscoveryDeprecationTest.php
@@ -19,11 +19,12 @@ class TestDiscoveryDeprecationTest extends KernelTestBase {
 
   /**
    * @expectedDeprecation The deprecated alter hook hook_simpletest_alter() is implemented in these functions: simpletest_deprecation_test_simpletest_alter. Convert your test to a PHPUnit-based one and implement test listeners. See: https://www.drupal.org/node/2939892
-   * @covers ::getTestClasses
+   * @covers ::alterHook
    */
   public function testHookSimpletestAlter() {
-    // The simpletest_test module implements hook_simpletest_alter(), which
-    // should trigger a deprecation error during getTestClasses().
+    // The simpletest_deprecation_test module implements
+    // hook_simpletest_alter(), which should trigger a deprecation error during
+    // getTestClasses().
     $this->assertNotEmpty(
       $this->container->get('test_discovery')->getTestClasses()
     );
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 3d9aa80170..a7853e86af 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -19,7 +19,7 @@
 use Drupal\Core\Test\TestRunnerKernel;
 use Drupal\simpletest\Form\SimpletestResultsForm;
 use Drupal\simpletest\TestBase;
-use Drupal\simpletest\TestDiscovery;
+use Drupal\Core\Test\TestDiscovery;
 use PHPUnit\Framework\TestCase;
 use PHPUnit\Runner\Version;
 use Symfony\Component\HttpFoundation\Request;
diff --git a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php
similarity index 96%
rename from core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php
rename to core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php
index fa3a93bf63..9d7c10cc62 100644
--- a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php
+++ b/core/tests/Drupal/Tests/Core/Test/TestDiscoveryTest.php
@@ -1,19 +1,20 @@
 <?php
 
-namespace Drupal\Tests\simpletest\Unit;
+namespace Drupal\Tests\Core\Test;
 
 use Composer\Autoload\ClassLoader;
 use Drupal\Core\DependencyInjection\Container;
 use Drupal\Core\DrupalKernel;
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Extension\ModuleHandlerInterface;
-use Drupal\simpletest\Exception\MissingGroupException;
-use Drupal\simpletest\TestDiscovery;
+use Drupal\Core\Test\Exception\MissingGroupException;
+use Drupal\Core\Test\TestDiscovery;
 use Drupal\Tests\UnitTestCase;
 use org\bovigo\vfs\vfsStream;
 
 /**
- * @coversDefaultClass \Drupal\simpletest\TestDiscovery
+ * @coversDefaultClass \Drupal\Core\Test\TestDiscovery
+ * @group Test
  * @group simpletest
  */
 class TestDiscoveryTest extends UnitTestCase {
@@ -33,9 +34,9 @@ public function infoParserProvider() {
       // Expected result.
       [
         'name' => static::class,
-        'group' => 'simpletest',
-        'groups' => ['simpletest'],
-        'description' => 'Tests \Drupal\simpletest\TestDiscovery.',
+        'group' => 'Test',
+        'groups' => ['Test', 'simpletest'],
+        'description' => 'Tests \Drupal\Core\Test\TestDiscovery.',
         'type' => 'PHPUnit-Unit',
       ],
       // Classname.
@@ -279,7 +280,10 @@ public function testTestInfoParserMissingGroup() {
  * Bulk delete storages and fields, and clean up afterwards.
  */
 EOT;
-    $this->setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest');
+    $this->setExpectedException(
+      MissingGroupException::class,
+      'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest'
+    );
     TestDiscovery::getTestInfo($classname, $doc_comment);
   }
 
@@ -367,9 +371,8 @@ class FunctionalExampleTest {}
   public function testGetTestClasses() {
     $this->setupVfsWithTestClasses();
     $class_loader = $this->prophesize(ClassLoader::class);
-    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
 
-    $test_discovery = new TestTestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal());
+    $test_discovery = new TestTestDiscovery('vfs://drupal', $class_loader->reveal());
 
     $extensions = [
       'test_module' => new Extension('vfs://drupal', 'module', 'modules/test_module/test_module.info.yml'),
diff --git a/core/tests/TestSuites/TestSuiteBase.php b/core/tests/TestSuites/TestSuiteBase.php
index 41ed61622b..06cfc537e9 100644
--- a/core/tests/TestSuites/TestSuiteBase.php
+++ b/core/tests/TestSuites/TestSuiteBase.php
@@ -2,7 +2,7 @@
 
 namespace Drupal\Tests\TestSuites;
 
-use Drupal\simpletest\TestDiscovery;
+use Drupal\Core\Test\TestDiscovery;
 use PHPUnit\Framework\TestSuite;
 
 /**
