diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php
index 626f4ba..d42a9a3 100644
--- a/core/tests/bootstrap.php
+++ b/core/tests/bootstrap.php
@@ -7,57 +7,14 @@
  * @see phpunit.xml.dist
  */
 
-/**
- * Finds all valid extension directories recursively within a given directory.
- *
- * @param string $scan_directory
- *   The directory that should be recursively scanned.
- * @return array
- *   An associative array of extension directories found within the scanned
- *   directory, keyed by extension name.
- */
-function drupal_phpunit_find_extension_directories($scan_directory) {
-  $extensions = array();
-  $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
-  foreach ($dirs as $dir) {
-    if (strpos($dir->getPathname(), '.info.yml') !== FALSE) {
-      // Cut off ".info.yml" from the filename for use as the extension name.
-      $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo()
-        ->getRealPath();
-    }
-  }
-  return $extensions;
-}
+$loader = require __DIR__ . '/../../autoload.php';
+require __DIR__ . '/../includes/bootstrap.inc';
 
-/**
- * Returns directories under which contributed extensions may exist.
- *
- * @return array
- *   An array of directories under which contributed extensions may exist.
- */
-function drupal_phpunit_contrib_extension_directory_roots() {
-  $root = dirname(dirname(__DIR__));
-  $paths = array(
-    $root . '/core/modules',
-    $root . '/core/profiles',
-    $root . '/modules',
-    $root . '/profiles',
-  );
-  $sites_path = $root . '/sites';
-  // Note this also checks sites/../modules and sites/../profiles.
-  foreach (scandir($sites_path) as $site) {
-    if ($site[0] === '.' || $site === 'simpletest') {
-      continue;
-    }
-    $path = "$sites_path/$site";
-    $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL;
-    $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL;
-  }
-  return array_filter($paths);
-}
+use Drupal\Core\Extension\Extension;
+use Drupal\Core\Extension\ExtensionDiscovery;
 
 /**
- * Registers the namespace for each extension directory with the autoloader.
+ * Create a classmap for the namespace within each extension directory.
  *
  * @param array $dirs
  *   An associative array of extension directories, keyed by extension name.
@@ -69,11 +26,11 @@ function drupal_phpunit_get_extension_namespaces($dirs) {
   $namespaces = array();
   foreach ($dirs as $extension => $dir) {
     if (is_dir($dir . '/src')) {
-      // Register the PSR-4 directory for module-provided classes.
+      // Create PSR-4 classmap for module-provided classes.
       $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src';
     }
     if (is_dir($dir . '/tests/src')) {
-      // Register the PSR-4 directory for PHPUnit test classes.
+      // Create PSR-4 classmap for PHPUnit test classes.
       $namespaces['Drupal\\Tests\\' . $extension . '\\'][] = $dir . '/tests/src';
     }
   }
@@ -88,16 +45,25 @@ function drupal_phpunit_get_extension_namespaces($dirs) {
   define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../autoload.php');
 }
 // Start with classes in known locations.
-$loader = require __DIR__ . '/../../autoload.php';
 $loader->add('Drupal\\Tests', __DIR__);
 $loader->add('Drupal\\KernelTests', __DIR__);
 
 if (!isset($GLOBALS['namespaces'])) {
   // Scan for arbitrary extension namespaces from core and contrib.
-  $extension_roots = drupal_phpunit_contrib_extension_directory_roots();
-
-  $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
-  $dirs = array_reduce($dirs, 'array_merge', array());
+  $root = dirname(dirname(__DIR__));
+  $extension_discovery = new ExtensionDiscovery($root, FALSE);
+  $extension_discovery->setProfileDirectories([$root . '/profiles']);
+  $extensions = [];
+  foreach(['profile', 'module'] as $type) {
+    // We must include test modules because some tests use them.
+    $extensions = array_merge($extension_discovery->scan($type, TRUE), $extensions);
+  }
+  // Grab only the directory path.
+  $dirs = [];
+  foreach ($extensions as $extension_name => $extension) {
+    // Use full path.
+    $dirs[$extension_name] = $root . '/' . $extension->getPath();
+  };
   $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs);
 }
 foreach ($GLOBALS['namespaces'] as $prefix => $paths) {
