diff --git a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
index 1164ba0..ee274e0 100644
--- a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
+++ b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
@@ -59,7 +59,6 @@ protected function setUp() {
 
     // Comment rendering generates links, so build the router.
     $this->installSchema('system', array('router'));
-    $this->container->get('router.builder')->rebuild();
 
     // Set up a field, so that the entity that'll be referenced bubbles up a
     // cache tag when rendering it entirely.
diff --git a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php
index 4545e46..ac2fe56 100644
--- a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php
+++ b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php
@@ -42,9 +42,6 @@ protected function setUp() {
     $this->installSchema('system', ['router']);
     $this->installConfig(['comment']);
 
-    // The entity.node.canonical route must exist when the RDF hook is called.
-    $this->container->get('router.builder')->rebuild();
-
     $this->migrateContent();
     $this->executeMigrations([
       'd6_comment_type',
diff --git a/core/modules/content_translation/src/Tests/ContentTranslationOperationsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationOperationsTest.php
index f987494..c794474 100644
--- a/core/modules/content_translation/src/Tests/ContentTranslationOperationsTest.php
+++ b/core/modules/content_translation/src/Tests/ContentTranslationOperationsTest.php
@@ -53,7 +53,6 @@ protected function setUp() {
     \Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedDefinitions();
-    \Drupal::service('router.builder')->rebuild();
     \Drupal::service('entity.definition_update_manager')->applyUpdates();
 
     $this->baseUser1 = $this->drupalCreateUser(['access content overview']);
diff --git a/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php b/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php
index ae088e0..aaa6085 100644
--- a/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php
+++ b/core/modules/dblog/src/Tests/Views/ViewsIntegrationTest.php
@@ -42,9 +42,6 @@ class ViewsIntegrationTest extends ViewKernelTestBase {
   protected function setUp() {
     parent::setUp();
 
-    // Rebuild the router, otherwise we can't generate links.
-    $this->container->get('router.builder')->rebuild();
-
     $this->installSchema('dblog', array('watchdog'));
 
     ViewTestData::createTestViews(get_class($this), array('dblog_test_views'));
diff --git a/core/modules/editor/src/Tests/EditorImageDialogTest.php b/core/modules/editor/src/Tests/EditorImageDialogTest.php
index b1745b0..cd92153 100644
--- a/core/modules/editor/src/Tests/EditorImageDialogTest.php
+++ b/core/modules/editor/src/Tests/EditorImageDialogTest.php
@@ -76,7 +76,6 @@ protected function setUp() {
     $type->save();
     node_add_body_field($type);
     $this->installEntitySchema('user');
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
index cc41f7d..d39cd54 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
@@ -76,7 +76,6 @@ protected function setUp() {
 
     // The label formatter rendering generates links, so build the router.
     $this->installSchema('system', 'router');
-    $this->container->get('router.builder')->rebuild();
 
     $this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType, 'default', array(), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
 
diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php
index e76145e..8358013 100644
--- a/core/modules/field/src/Tests/FieldAttachOtherTest.php
+++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php
@@ -19,7 +19,6 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
 
   protected function setUp() {
     parent::setUp();
-    $this->container->get('router.builder')->rebuild();
     $this->installEntitySchema('entity_test_rev');
     $this->createFieldWithStorage();
   }
diff --git a/core/modules/field/src/Tests/String/RawStringFormatterTest.php b/core/modules/field/src/Tests/String/RawStringFormatterTest.php
index 60ea420..a5d3722 100644
--- a/core/modules/field/src/Tests/String/RawStringFormatterTest.php
+++ b/core/modules/field/src/Tests/String/RawStringFormatterTest.php
@@ -59,7 +59,6 @@ protected function setUp() {
     // Configure the theme system.
     $this->installConfig(array('system', 'field'));
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
     $this->installEntitySchema('entity_test');
 
     $this->entityType = 'entity_test';
diff --git a/core/modules/field/src/Tests/String/StringFormatterTest.php b/core/modules/field/src/Tests/String/StringFormatterTest.php
index 1703c3e..28ec21c 100644
--- a/core/modules/field/src/Tests/String/StringFormatterTest.php
+++ b/core/modules/field/src/Tests/String/StringFormatterTest.php
@@ -59,7 +59,6 @@ protected function setUp() {
     // Configure the theme system.
     $this->installConfig(array('system', 'field'));
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
     $this->installEntitySchema('entity_test_rev');
 
     $this->entityType = 'entity_test_rev';
diff --git a/core/modules/field/src/Tests/String/UuidFormatterTest.php b/core/modules/field/src/Tests/String/UuidFormatterTest.php
index 92554bf..af34d3f 100644
--- a/core/modules/field/src/Tests/String/UuidFormatterTest.php
+++ b/core/modules/field/src/Tests/String/UuidFormatterTest.php
@@ -33,7 +33,6 @@ protected function setUp() {
 
     $this->installConfig(['system', 'field']);
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
     $this->installEntitySchema('entity_test');
   }
 
diff --git a/core/modules/filter/src/Tests/TextFormatElementFormTest.php b/core/modules/filter/src/Tests/TextFormatElementFormTest.php
index b889c4a..56450ff 100644
--- a/core/modules/filter/src/Tests/TextFormatElementFormTest.php
+++ b/core/modules/filter/src/Tests/TextFormatElementFormTest.php
@@ -43,8 +43,6 @@ protected function setUp() {
     $this->installEntitySchema('user');
     $this->installSchema('system', ['sequences', 'router']);
     $this->installConfig(['filter', 'filter_test']);
-    // Filter tips link to the full-page.
-    \Drupal::service('router.builder')->rebuild();
     /* @var \Drupal\Core\Render\ElementInfoManager $manager */
     $manager = \Drupal::service('plugin.manager.element_info');
     $manager->clearCachedDefinitions();
diff --git a/core/modules/hal/src/Tests/EntityTest.php b/core/modules/hal/src/Tests/EntityTest.php
index 6301fb0..68827ab 100644
--- a/core/modules/hal/src/Tests/EntityTest.php
+++ b/core/modules/hal/src/Tests/EntityTest.php
@@ -31,7 +31,6 @@ class EntityTest extends NormalizerTestBase {
   protected function setUp() {
     parent::setUp();
 
-    \Drupal::service('router.builder')->rebuild();
     $this->installSchema('system', array('sequences'));
     $this->installSchema('comment', array('comment_entity_statistics'));
     $this->installEntitySchema('taxonomy_term');
diff --git a/core/modules/hal/src/Tests/NormalizeTest.php b/core/modules/hal/src/Tests/NormalizeTest.php
index 0f24d73..72e413c 100644
--- a/core/modules/hal/src/Tests/NormalizeTest.php
+++ b/core/modules/hal/src/Tests/NormalizeTest.php
@@ -18,15 +18,6 @@
 class NormalizeTest extends NormalizerTestBase {
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    \Drupal::service('router.builder')->rebuild();
-  }
-
-  /**
    * Tests the normalize function.
    */
   public function testNormalize() {
diff --git a/core/modules/language/src/Tests/EntityUrlLanguageTest.php b/core/modules/language/src/Tests/EntityUrlLanguageTest.php
index 915f7f6..bbd8db4 100644
--- a/core/modules/language/src/Tests/EntityUrlLanguageTest.php
+++ b/core/modules/language/src/Tests/EntityUrlLanguageTest.php
@@ -30,7 +30,6 @@ protected function setUp() {
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('configurable_language');
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
 
     // In order to reflect the changes for a multilingual site in the container
     // we have to rebuild it.
diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
index d83f871..078ecb3 100644
--- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
+++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
@@ -200,15 +200,16 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
 
     // The menu link can just be updated if there is already an menu link entry
     // on both entity and menu link plugin level.
-    if ($update && $menu_link_manager->getDefinition($this->getPluginId())) {
+    $definition = $this->getPluginDefinition();
+    if ($menu_link_manager->getDefinition($this->getPluginId(), FALSE)) {
       // When the entity is saved via a plugin instance, we should not call
       // the menu tree manager to update the definition a second time.
       if (!$this->insidePlugin) {
-        $menu_link_manager->updateDefinition($this->getPluginId(), $this->getPluginDefinition(), FALSE);
+        $menu_link_manager->updateDefinition($this->getPluginId(), $definition, FALSE);
       }
     }
     else {
-      $menu_link_manager->addDefinition($this->getPluginId(), $this->getPluginDefinition());
+      $menu_link_manager->addDefinition($this->getPluginId(), $definition);
     }
   }
 
diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentCacheabilityBubblingTest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentCacheabilityBubblingTest.php
index 825f493..b8e4750 100644
--- a/core/modules/menu_link_content/src/Tests/MenuLinkContentCacheabilityBubblingTest.php
+++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentCacheabilityBubblingTest.php
@@ -50,8 +50,6 @@ protected function setUp() {
    * Tests bubbleable metadata of menu links' outbound route/path processing.
    */
   public function testOutboundPathAndRouteProcessing() {
-    \Drupal::service('router.builder')->rebuild();
-
     $request_stack = \Drupal::requestStack();
     /** @var \Symfony\Component\Routing\RequestContext $request_context */
     $request_context = \Drupal::service('router.request_context');
diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php
index b5ae7ae..33a1667 100644
--- a/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php
+++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php
@@ -43,7 +43,6 @@ public function testRediscover() {
     \Drupal::state()->set('menu_link_content_dynamic_route.routes', [
       'route_name_1' => new Route('/example-path'),
     ]);
-    \Drupal::service('router.builder')->rebuild();
 
     // Set up a custom menu link pointing to a specific path.
     $parent = MenuLinkContent::create([
diff --git a/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php b/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
index 3cdec3f..f8ac2bc 100644
--- a/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
+++ b/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
@@ -55,8 +55,6 @@ public function containerBuild(ContainerBuilder $container) {
    * Tests the path aliasing changing.
    */
   public function testPathAliasChange() {
-    \Drupal::service('router.builder')->rebuild();
-
     /** @var \Drupal\Core\Path\AliasStorageInterface $path_alias_storage */
     $path_alias_storage = \Drupal::service('path.alias_storage');
     $alias = $path_alias_storage->save('/test-page', '/my-blog');
diff --git a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php
index fcfe4f8..b28284c 100644
--- a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php
+++ b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php
@@ -55,7 +55,6 @@
    */
   protected function setUp() {
     parent::setUp();
-    $this->container->get('router.builder')->rebuild();
 
     $this->fieldStorageDefinition = array(
       'field_name' => $this->fieldName,
diff --git a/core/modules/rest/src/Tests/RestLinkManagerTest.php b/core/modules/rest/src/Tests/RestLinkManagerTest.php
index 4adee7c..5bb97f3 100644
--- a/core/modules/rest/src/Tests/RestLinkManagerTest.php
+++ b/core/modules/rest/src/Tests/RestLinkManagerTest.php
@@ -26,7 +26,6 @@ class RestLinkManagerTest extends KernelTestBase {
   protected function setUp() {
     parent::setUp();
     $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/serialization/src/Tests/EntityResolverTest.php b/core/modules/serialization/src/Tests/EntityResolverTest.php
index f63d96d..baa34e4 100644
--- a/core/modules/serialization/src/Tests/EntityResolverTest.php
+++ b/core/modules/serialization/src/Tests/EntityResolverTest.php
@@ -32,8 +32,6 @@ class EntityResolverTest extends NormalizerTestBase {
   protected function setUp() {
     parent::setUp();
 
-    \Drupal::service('router.builder')->rebuild();
-
     // Create the test field storage.
     entity_create('field_storage_config', array(
       'entity_type' => 'entity_test_mulrev',
diff --git a/core/modules/serialization/src/Tests/NormalizerTestBase.php b/core/modules/serialization/src/Tests/NormalizerTestBase.php
index c38c554..3540a28 100644
--- a/core/modules/serialization/src/Tests/NormalizerTestBase.php
+++ b/core/modules/serialization/src/Tests/NormalizerTestBase.php
@@ -25,7 +25,6 @@ protected function setUp() {
     $this->installEntitySchema('user');
     $this->installSchema('system', array('url_alias', 'router'));
     $this->installConfig(array('field'));
-    \Drupal::service('router.builder')->rebuild();
     \Drupal::moduleHandler()->invoke('rest', 'install');
 
     // Auto-create a field for testing.
diff --git a/core/modules/simpletest/src/RouteProvider.php b/core/modules/simpletest/src/RouteProvider.php
new file mode 100644
index 0000000..04c6383
--- /dev/null
+++ b/core/modules/simpletest/src/RouteProvider.php
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\ProxyClass\Routing\RouteProvider.
+ */
+
+namespace Drupal\simpletest;
+
+use Drupal\Core\Routing\PreloadableRouteProviderInterface;
+use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Rebuilds the router when the provider is instantiated.
+ */
+class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface, EventSubscriberInterface {
+
+  use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
+
+  /**
+   * Loads the real route provider from the container and rebuilds the router.
+   *
+   * @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface
+   *   The route provider.
+   */
+  protected function lazyLoadItself() {
+    if (!isset($this->service)) {
+      $container = \Drupal::getContainer();
+      $this->service = $container->get('simpletest.router.route_provider');
+      $container->get('router.builder')->rebuild();
+    }
+
+    return $this->service;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRouteCollectionForRequest(Request $request) {
+    return $this->lazyLoadItself()->getRouteCollectionForRequest($request);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRouteByName($name) {
+    return $this->lazyLoadItself()->getRouteByName($name);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function preLoadRoutes($names){
+    return $this->lazyLoadItself()->preLoadRoutes($names);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRoutesByNames($names) {
+    return $this->lazyLoadItself()->getRoutesByNames($names);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCandidateOutlines(array $parts) {
+    return $this->lazyLoadItself()->getCandidateOutlines($parts);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRoutesByPattern($pattern) {
+    return $this->lazyLoadItself()->getRoutesByPattern($pattern);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function routeProviderRouteCompare(array $a, array $b) {
+    return $this->lazyLoadItself()->routeProviderRouteCompare($a, $b);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getAllRoutes() {
+    return $this->lazyLoadItself()->getAllRoutes();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function reset() {
+    return $this->lazyLoadItself()->reset();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getSubscribedEvents() {
+    RouteProvider::getSubscribedEvents();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRoutesPaged($offset, $length = NULL) {
+    return $this->lazyLoadItself()->getRoutesPaged($offset, $length);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRoutesCount() {
+    return $this->lazyLoadItself()->getRoutesCount();
+  }
+
+}
diff --git a/core/modules/simpletest/src/TestServiceProvider.php b/core/modules/simpletest/src/TestServiceProvider.php
index 64dedb8..9ba565a 100644
--- a/core/modules/simpletest/src/TestServiceProvider.php
+++ b/core/modules/simpletest/src/TestServiceProvider.php
@@ -8,9 +8,11 @@
 namespace Drupal\simpletest;
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\DependencyInjection\ServiceModifierInterface;
 use Drupal\Core\DependencyInjection\ServiceProviderInterface;
+use Symfony\Component\DependencyInjection\Definition;
 
-class TestServiceProvider implements ServiceProviderInterface {
+class TestServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
 
   /**
    * @var \Drupal\simpletest\TestBase;
@@ -25,4 +27,17 @@ function register(ContainerBuilder $container) {
       static::$currentTest->containerBuild($container);
     }
   }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function alter(ContainerBuilder $container) {
+    if (static::$currentTest instanceof KernelTestBase) {
+      // While $container->get() does a recursive resolve, getDefinition() does
+      // not so do it ourselves.
+      for ($id = 'router.route_provider'; $container->hasAlias($id); $id = (string) $container->getAlias($id));
+      $container->setDefinition('simpletest.router.route_provider', $container->getDefinition($id));
+      $container->setDefinition('router.route_provider', new Definition('Drupal\simpletest\RouteProvider'));
+    }
+  }
 }
diff --git a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
index 7440d99..48623c0 100644
--- a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
+++ b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
@@ -52,8 +52,6 @@ class AttachedAssetsTest extends KernelTestBase {
   protected function setUp() {
     parent::setUp();
     $this->installSchema('system', array('router'));
-    $this->container->get('router.builder')->rebuild();
-
     $this->assetResolver = $this->container->get('asset.resolver');
     $this->renderer = $this->container->get('renderer');
   }
diff --git a/core/modules/system/src/Tests/Common/PageRenderTest.php b/core/modules/system/src/Tests/Common/PageRenderTest.php
index 1b4c387..a8b70c1 100644
--- a/core/modules/system/src/Tests/Common/PageRenderTest.php
+++ b/core/modules/system/src/Tests/Common/PageRenderTest.php
@@ -22,8 +22,6 @@ class PageRenderTest extends KernelTestBase {
   function testHookPageAttachmentsExceptions() {
     $this->enableModules(['common_test', 'system']);
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
-
     $this->assertPageRenderHookExceptions('common_test', 'hook_page_attachments');
   }
 
@@ -33,8 +31,6 @@ function testHookPageAttachmentsExceptions() {
   function testHookPageAlter() {
     $this->enableModules(['common_test', 'system']);
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
-
     $this->assertPageRenderHookExceptions('common_test', 'hook_page_attachments_alter');
   }
 
diff --git a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
index b71b9c1..723500a 100644
--- a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
+++ b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
@@ -29,7 +29,6 @@ protected function setUp() {
     parent::setUp();
     $this->installConfig(array('system'));
     $this->installSchema('system', array('router'));
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/system/src/Tests/Element/PathElementFormTest.php b/core/modules/system/src/Tests/Element/PathElementFormTest.php
index bcbe534..ebfba8e 100644
--- a/core/modules/system/src/Tests/Element/PathElementFormTest.php
+++ b/core/modules/system/src/Tests/Element/PathElementFormTest.php
@@ -44,7 +44,6 @@ protected function setUp() {
     parent::setUp();
     $this->installSchema('system', ['router', 'sequences', 'key_value_expire']);
     $this->installEntitySchema('user');
-    \Drupal::service('router.builder')->rebuild();
     /** @var \Drupal\user\RoleInterface $role */
     $role = Role::create(array(
       'id' => 'admin',
diff --git a/core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php b/core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php
index 0fdd9af..c8b28e6 100644
--- a/core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php
+++ b/core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php
@@ -51,7 +51,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', ['router', 'key_value_expire']);
-    \Drupal::service('router.builder')->rebuild();
 
     $this->testUser = User::create(array(
       'name' => 'foobar1',
diff --git a/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php b/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
index 4f223e3..d2ed9af 100644
--- a/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
+++ b/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
@@ -30,7 +30,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', ['router', 'key_value']);
-    $this->container->get('router.builder')->rebuild();
 
     $this->installEntitySchema('user');
     $this->installEntitySchema('entity_test_composite_constraint');
diff --git a/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php b/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php
index 3096310..b63ea0d 100644
--- a/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php
+++ b/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php
@@ -33,7 +33,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/system/src/Tests/Render/Element/TableTest.php b/core/modules/system/src/Tests/Render/Element/TableTest.php
index 725f339..c45fd06 100644
--- a/core/modules/system/src/Tests/Render/Element/TableTest.php
+++ b/core/modules/system/src/Tests/Render/Element/TableTest.php
@@ -30,7 +30,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php b/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php
index 551e4d8..0fdd38e 100644
--- a/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php
+++ b/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php
@@ -43,8 +43,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
-
     $this->urlGenerator = \Drupal::urlGenerator();
   }
 
diff --git a/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php b/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php
index bc341a6..addaf1d 100644
--- a/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php
+++ b/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php
@@ -42,8 +42,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
-
     $this->urlGenerator = \Drupal::urlGenerator();
   }
 
diff --git a/core/modules/system/src/Tests/Routing/ContentNegotiationRoutingTest.php b/core/modules/system/src/Tests/Routing/ContentNegotiationRoutingTest.php
index 98515b8..c2a4164 100644
--- a/core/modules/system/src/Tests/Routing/ContentNegotiationRoutingTest.php
+++ b/core/modules/system/src/Tests/Routing/ContentNegotiationRoutingTest.php
@@ -32,7 +32,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', ['router', 'url_alias']);
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
@@ -123,7 +122,6 @@ function testContentRouting() {
    */
   public function testFullNegotiation() {
     $this->enableModules(['accept_header_routing_test']);
-    \Drupal::service('router.builder')->rebuild();
     $tests = [
       // ['path', 'accept', 'content-type'],
 
diff --git a/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php b/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php
index ee3b6eb..eeaff18 100644
--- a/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php
+++ b/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php
@@ -31,7 +31,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php b/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php
index 66239c9..67ce57e 100644
--- a/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php
+++ b/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php
@@ -39,7 +39,6 @@ protected function setUp() {
    * Ensures that the access() method on \Drupal\Core\Url objects works.
    */
   public function testAccess() {
-    \Drupal::service('router.builder')->rebuild();
     /** @var \Drupal\user\RoleInterface $role_with_access */
     $role_with_access = Role::create(['id' => 'role_with_access']);
     $role_with_access->grantPermission('administer users');
diff --git a/core/modules/system/src/Tests/System/TokenReplaceUnitTestBase.php b/core/modules/system/src/Tests/System/TokenReplaceUnitTestBase.php
index 95ed3f5..84b5041 100644
--- a/core/modules/system/src/Tests/System/TokenReplaceUnitTestBase.php
+++ b/core/modules/system/src/Tests/System/TokenReplaceUnitTestBase.php
@@ -40,8 +40,6 @@ protected function setUp() {
     // Install default system configuration.
     $this->installConfig(array('system'));
     $this->installSchema('system', array('router'));
-    \Drupal::service('router.builder')->rebuild();
-
     $this->interfaceLanguage = \Drupal::languageManager()->getCurrentLanguage();
     $this->tokenService = \Drupal::token();
   }
diff --git a/core/modules/system/src/Tests/System/TrustedHostsTest.php b/core/modules/system/src/Tests/System/TrustedHostsTest.php
index a3b08b8..d9da707 100644
--- a/core/modules/system/src/Tests/System/TrustedHostsTest.php
+++ b/core/modules/system/src/Tests/System/TrustedHostsTest.php
@@ -65,7 +65,6 @@ public function testStatusPageWithConfiguration() {
    */
   public function testFakeRequests() {
     $this->container->get('module_installer')->install(['trusted_hosts_test']);
-    $this->container->get('router.builder')->rebuild();
 
     $host = $this->container->get('request_stack')->getCurrentRequest()->getHost();
     $settings['settings']['trusted_host_patterns'] = (object) array(
@@ -85,7 +84,6 @@ public function testFakeRequests() {
   public function testShortcut() {
     $this->container->get('module_installer')->install(['block', 'shortcut']);
     $this->rebuildContainer();
-    $this->container->get('router.builder')->rebuild();
 
     /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
     $entity_manager = $this->container->get('entity.manager');
diff --git a/core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php b/core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php
index ef87848..d48bf03 100644
--- a/core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php
+++ b/core/modules/taxonomy/src/Tests/TaxonomyTranslationTestTrait.php
@@ -72,7 +72,6 @@ protected function enableTranslation() {
     \Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary->id(), TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedDefinitions();
-    \Drupal::service('router.builder')->rebuild();
     \Drupal::service('entity.definition_update_manager')->applyUpdates();
   }
 
diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php
index d58b2d5..8456931 100644
--- a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php
+++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php
@@ -93,7 +93,6 @@ function setUp() {
     Views::viewsData()->clear();
 
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
-    $this->container->get('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
index 679eec0..2a19787 100644
--- a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
+++ b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
@@ -78,9 +78,8 @@ function testUserEditForm() {
     // Install default configuration; required for AccountFormController.
     $this->installConfig(array('user'));
 
-    // Install the router table and then rebuild.
+    // Install the router table.
     $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
 
     $form = $this->buildAccountForm('default');
 
diff --git a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
index f69444a..d75b9ad 100644
--- a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
+++ b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
@@ -59,9 +59,6 @@ protected function setUp() {
     $this->installSchema('node', array('node_access'));
     $this->installConfig(array('node', 'language'));
 
-    // The entity.node.canonical route must exist when nodes are rendered.
-    $this->container->get('router.builder')->rebuild();
-
     $this->langcodes = array(\Drupal::languageManager()->getDefaultLanguage()->getId());
     for ($i = 0; $i < 2; $i++) {
       $langcode = 'l' . $i;
diff --git a/core/modules/views/src/Tests/Plugin/DisplayTest.php b/core/modules/views/src/Tests/Plugin/DisplayTest.php
index 0517063..757ef60 100644
--- a/core/modules/views/src/Tests/Plugin/DisplayTest.php
+++ b/core/modules/views/src/Tests/Plugin/DisplayTest.php
@@ -357,7 +357,6 @@ public function testOutputIsEmpty() {
    */
   public function testTranslationSetting() {
     \Drupal::service('module_installer')->install(['file']);
-    \Drupal::service('router.builder')->rebuild();
 
     // By default there should be no language settings.
     $this->checkTranslationSetting();
diff --git a/core/modules/views/src/Tests/Plugin/RowEntityTest.php b/core/modules/views/src/Tests/Plugin/RowEntityTest.php
index 9723750..7e79214 100644
--- a/core/modules/views/src/Tests/Plugin/RowEntityTest.php
+++ b/core/modules/views/src/Tests/Plugin/RowEntityTest.php
@@ -41,7 +41,6 @@ protected function setUp() {
 
     $this->installEntitySchema('taxonomy_term');
     $this->installConfig(array('taxonomy'));
-    \Drupal::service('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/views/src/Tests/TokenReplaceTest.php b/core/modules/views/src/Tests/TokenReplaceTest.php
index 0462756..d724eb3 100644
--- a/core/modules/views/src/Tests/TokenReplaceTest.php
+++ b/core/modules/views/src/Tests/TokenReplaceTest.php
@@ -29,7 +29,6 @@ class TokenReplaceTest extends ViewKernelTestBase {
   protected function setUp() {
     parent::setUp();
     $this->installSchema('system', 'url_alias');
-    $this->container->get('router.builder')->rebuild();
   }
 
   /**
diff --git a/core/modules/views/src/Tests/ViewKernelTestBase.php b/core/modules/views/src/Tests/ViewKernelTestBase.php
index fe794ea..a45d89d 100644
--- a/core/modules/views/src/Tests/ViewKernelTestBase.php
+++ b/core/modules/views/src/Tests/ViewKernelTestBase.php
@@ -46,7 +46,7 @@ protected function setUp($import_test_views = TRUE) {
     $this->setUpFixtures();
 
     if ($import_test_views) {
-      ViewTestData::createTestViews(get_class($this), array('views_test_config'));
+      ViewTestData::createTestViews(get_class($this), array('views_test_config'), FALSE);
     }
   }
 
@@ -70,8 +70,6 @@ protected function setUpFixtures() {
       $this->installSchema('views_test_data', $table);
     }
 
-    \Drupal::service('router.builder')->rebuild();
-
     // Load the test dataset.
     $data_set = $this->dataSet();
     $query = db_insert('views_test_data')
diff --git a/core/modules/views/src/Tests/ViewTestData.php b/core/modules/views/src/Tests/ViewTestData.php
index 536470c..7b002be 100644
--- a/core/modules/views/src/Tests/ViewTestData.php
+++ b/core/modules/views/src/Tests/ViewTestData.php
@@ -26,8 +26,10 @@ class ViewTestData {
    *   The name of the test class. Installs the listed test views *in order*.
    * @param array $modules
    *   The module directories to look in for test views.
+   * @param bool $rebuild
+   *   TRUE to run a router rebuild. Kernel tests do not need this.
    */
-  public static function createTestViews($class, array $modules) {
+  public static function createTestViews($class, array $modules, $rebuild = TRUE) {
     $views = array();
     while ($class) {
       if (property_exists($class, 'testViews')) {
@@ -57,8 +59,10 @@ public static function createTestViews($class, array $modules) {
       }
     }
 
-    // Rebuild the router once.
-    \Drupal::service('router.builder')->rebuild();
+    if ($rebuild) {
+      // Rebuild the router once.
+      \Drupal::service('router.builder')->rebuild();
+    }
   }
 
   /**
