diff --git a/core/modules/simpletest/src/RouteProvider.php b/core/modules/simpletest/src/RouteProvider.php
index acff99a..0784d72 100644
--- a/core/modules/simpletest/src/RouteProvider.php
+++ b/core/modules/simpletest/src/RouteProvider.php
@@ -13,6 +13,9 @@
 
 /**
  * Rebuilds the router when the provider is instantiated.
+ *
+ * @todo Move this outside of simpletest namespace to the Drupal\Tests, see
+ *   https://www.drupal.org/node/2672762
  */
 class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
 
diff --git a/core/modules/simpletest/src/TestServiceProvider.php b/core/modules/simpletest/src/TestServiceProvider.php
index 5a1a398..ba65c37 100644
--- a/core/modules/simpletest/src/TestServiceProvider.php
+++ b/core/modules/simpletest/src/TestServiceProvider.php
@@ -33,15 +33,25 @@ function register(ContainerBuilder $container) {
    */
   public function alter(ContainerBuilder $container) {
     if (static::$currentTest instanceof KernelTestBase) {
-      // While $container->get() does a recursive resolve, getDefinition() does
-      // not, so do it ourselves.
-      foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
-        for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id));
-        $definition = $container->getDefinition($id);
-        $definition->clearTag('needs_destruction');
-        $container->setDefinition("simpletest.$original_id", $definition);
-        $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
-      }
+      static::addRouteProvider($container);
     }
   }
+
+  /**
+   * Add the on demand rebuild route provider service.
+   *
+   * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
+   */
+  public static function addRouteProvider(ContainerBuilder $container) {
+    foreach (['router.route_provider' => 'RouteProvider'] as $original_id => $class) {
+      // While $container->get() does a recursive resolve, getDefinition() does
+      // not, so do it ourselves.
+      for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id));
+      $definition = $container->getDefinition($id);
+      $definition->clearTag('needs_destruction');
+      $container->setDefinition("simpletest.$original_id", $definition);
+      $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
+    }
+  }
+
 }
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php b/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php
index 9199c74..c97f03a 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/RouteProviderTest.php
@@ -37,13 +37,6 @@ protected function setUp() {
     $this->installEntitySchema('entity_test_mul');
     $this->installEntitySchema('entity_test_admin_routes');
 
-    $router_builder = \Drupal::service('router.builder');
-    $router_builder->rebuild();
-
-    /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
-    $router_builder = \Drupal::service('router.builder');
-    $router_builder->rebuild();
-
     /** @var \Drupal\user\RoleInterface $role */
     $role = Role::create([
       'id' => RoleInterface::ANONYMOUS_ID
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index f1a1414..bc62103 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -25,6 +25,7 @@
 use Drupal\simpletest\AssertContentTrait;
 use Drupal\simpletest\AssertHelperTrait;
 use Drupal\simpletest\RandomGeneratorTrait;
+use Drupal\simpletest\TestServiceProvider;
 use Symfony\Component\DependencyInjection\Reference;
 use Symfony\Component\HttpFoundation\Request;
 use org\bovigo\vfs\vfsStream;
@@ -595,6 +596,7 @@ public function register(ContainerBuilder $container) {
       $container->getDefinition('password')
         ->setArguments(array(1));
     }
+    TestServiceProvider::addRouteProvider($container);
   }
 
   /**
