diff --git a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php
index 942239b..0b132a9 100644
--- a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php
+++ b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php
@@ -24,7 +24,6 @@ class BreakpointDiscoveryTest extends KernelTestBase {
 
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', array('router'));
     \Drupal::service('theme_handler')->install(array('breakpoint_theme_test'));
   }
 
diff --git a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
index 1164ba0..a0ca5f2 100644
--- a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
+++ b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
@@ -57,10 +57,6 @@ protected function setUp() {
     $this->installSchema('comment', array('comment_entity_statistics'));
     $this->installConfig(array('system', 'filter', 'comment'));
 
-    // 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.
     $this->addDefaultCommentField('entity_test', 'entity_test');
diff --git a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php
index 4545e46..93ee0c0 100644
--- a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php
+++ b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php
@@ -39,12 +39,8 @@ protected function setUp() {
     $this->installEntitySchema('node');
     $this->installEntitySchema('comment');
     $this->installSchema('comment', ['comment_entity_statistics']);
-    $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/config/src/Tests/ConfigInstallTest.php b/core/modules/config/src/Tests/ConfigInstallTest.php
index e5ac68d..f0d25b1 100644
--- a/core/modules/config/src/Tests/ConfigInstallTest.php
+++ b/core/modules/config/src/Tests/ConfigInstallTest.php
@@ -30,8 +30,6 @@ class ConfigInstallTest extends KernelTestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', ['router']);
-
     // Ensure the global variable being asserted by this test does not exist;
     // a previous test executed in this request/process might have set it.
     unset($GLOBALS['hook_config_test']);
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..efd79c3 100644
--- a/core/modules/editor/src/Tests/EditorImageDialogTest.php
+++ b/core/modules/editor/src/Tests/EditorImageDialogTest.php
@@ -41,7 +41,7 @@ class EditorImageDialogTest extends EntityUnitTestBase {
   protected function setUp() {
     parent::setUp();
     $this->installEntitySchema('file');
-    $this->installSchema('system', ['router', 'key_value_expire']);
+    $this->installSchema('system', 'key_value_expire');
     $this->installSchema('node', array('node_access'));
     $this->installSchema('file', array('file_usage'));
     $this->installConfig(['node']);
@@ -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..e511305 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
@@ -74,10 +74,6 @@ protected function setUp() {
       ->grantPermission('view test entity')
       ->save();
 
-    // 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);
 
     // Set up a field, so that the entity that'll be referenced bubbles up a
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/FieldUnitTestBase.php b/core/modules/field/src/Tests/FieldUnitTestBase.php
index ddcf3f9..b0cfd94 100644
--- a/core/modules/field/src/Tests/FieldUnitTestBase.php
+++ b/core/modules/field/src/Tests/FieldUnitTestBase.php
@@ -50,7 +50,7 @@ protected function setUp() {
 
     $this->installEntitySchema('entity_test');
     $this->installEntitySchema('user');
-    $this->installSchema('system', ['router', 'sequences', 'key_value']);
+    $this->installSchema('system', ['sequences', 'key_value']);
 
     // Set default storage backend and configure the theme system.
     $this->installConfig(array('field', 'system'));
diff --git a/core/modules/field/src/Tests/String/RawStringFormatterTest.php b/core/modules/field/src/Tests/String/RawStringFormatterTest.php
index 60ea420..59fde5f 100644
--- a/core/modules/field/src/Tests/String/RawStringFormatterTest.php
+++ b/core/modules/field/src/Tests/String/RawStringFormatterTest.php
@@ -58,8 +58,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..c5a1dc2 100644
--- a/core/modules/field/src/Tests/String/StringFormatterTest.php
+++ b/core/modules/field/src/Tests/String/StringFormatterTest.php
@@ -58,8 +58,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..a4e971e 100644
--- a/core/modules/field/src/Tests/String/UuidFormatterTest.php
+++ b/core/modules/field/src/Tests/String/UuidFormatterTest.php
@@ -32,8 +32,6 @@ protected function setUp() {
     parent::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..0c13574 100644
--- a/core/modules/filter/src/Tests/TextFormatElementFormTest.php
+++ b/core/modules/filter/src/Tests/TextFormatElementFormTest.php
@@ -41,10 +41,8 @@ class TextFormatElementFormTest extends KernelTestBase implements FormInterface
   protected function setUp() {
     parent::setUp();
     $this->installEntitySchema('user');
-    $this->installSchema('system', ['sequences', 'router']);
+    $this->installSchema('system', 'sequences');
     $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/hal/src/Tests/NormalizerTestBase.php b/core/modules/hal/src/Tests/NormalizerTestBase.php
index 104a5e2..4a64ba5 100644
--- a/core/modules/hal/src/Tests/NormalizerTestBase.php
+++ b/core/modules/hal/src/Tests/NormalizerTestBase.php
@@ -61,7 +61,7 @@
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', array('url_alias', 'router'));
+    $this->installSchema('system', 'url_alias');
     $this->installEntitySchema('user');
     $this->installEntitySchema('entity_test');
     // If the concrete test sub-class installs the Node or Comment modules,
@@ -83,7 +83,6 @@ protected function setUp() {
       $class = get_parent_class($class);
     }
     $this->installConfig(array('field', 'language'));
-    \Drupal::service('router.builder')->rebuild();
 
     // Add German as a language.
     ConfigurableLanguage::create(array(
diff --git a/core/modules/help/src/Tests/HelpEmptyPageTest.php b/core/modules/help/src/Tests/HelpEmptyPageTest.php
index 5fd1339..e0c1f35 100644
--- a/core/modules/help/src/Tests/HelpEmptyPageTest.php
+++ b/core/modules/help/src/Tests/HelpEmptyPageTest.php
@@ -27,15 +27,6 @@ class HelpEmptyPageTest extends KernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->installSchema('system', 'router');
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function containerBuild(ContainerBuilder $container) {
     parent::containerBuild($container);
 
diff --git a/core/modules/language/src/Tests/EntityUrlLanguageTest.php b/core/modules/language/src/Tests/EntityUrlLanguageTest.php
index 915f7f6..ee087a6 100644
--- a/core/modules/language/src/Tests/EntityUrlLanguageTest.php
+++ b/core/modules/language/src/Tests/EntityUrlLanguageTest.php
@@ -29,8 +29,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..7fcb960 100644
--- a/core/modules/menu_link_content/src/Tests/MenuLinkContentCacheabilityBubblingTest.php
+++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentCacheabilityBubblingTest.php
@@ -39,7 +39,7 @@ protected function setUp() {
 
     $this->installEntitySchema('menu_link_content');
     $this->installEntitySchema('user');
-    $this->installSchema('system', ['url_alias', 'router']);
+    $this->installSchema('system', 'url_alias');
 
     // Ensure that the weight of module_link_content is higher than system.
     // @see menu_link_content_install()
@@ -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..6fec4ab 100644
--- a/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php
+++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php
@@ -33,7 +33,6 @@ protected function setUp() {
     parent::setUp();
 
     $this->installEntitySchema('menu_link_content');
-    $this->installSchema('system', 'router');
   }
 
   /**
@@ -43,7 +42,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/Migrate/d6/MigrateMenuLinkTest.php b/core/modules/menu_link_content/src/Tests/Migrate/d6/MigrateMenuLinkTest.php
index f6346fc..795f5f0 100644
--- a/core/modules/menu_link_content/src/Tests/Migrate/d6/MigrateMenuLinkTest.php
+++ b/core/modules/menu_link_content/src/Tests/Migrate/d6/MigrateMenuLinkTest.php
@@ -27,7 +27,6 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', ['router']);
     $this->installEntitySchema('menu_link_content');
     $this->executeMigrations(['menu', 'd6_menu_links']);
   }
diff --git a/core/modules/menu_link_content/src/Tests/Migrate/d7/MigrateMenuLinkTest.php b/core/modules/menu_link_content/src/Tests/Migrate/d7/MigrateMenuLinkTest.php
index 6b9814a..cd18579 100644
--- a/core/modules/menu_link_content/src/Tests/Migrate/d7/MigrateMenuLinkTest.php
+++ b/core/modules/menu_link_content/src/Tests/Migrate/d7/MigrateMenuLinkTest.php
@@ -29,7 +29,6 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', ['router']);
     $this->installEntitySchema('menu_link_content');
     $this->executeMigration('menu');
   }
diff --git a/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php b/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
index 3cdec3f..50de241 100644
--- a/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
+++ b/core/modules/menu_link_content/src/Tests/PathAliasMenuLinkContentTest.php
@@ -32,7 +32,7 @@ protected function setUp() {
     parent::setUp();
 
     $this->installEntitySchema('menu_link_content');
-    $this->installSchema('system', ['url_alias', 'router']);
+    $this->installSchema('system', 'url_alias');
 
     // Ensure that the weight of module_link_content is higher than system.
     // @see menu_link_content_install()
@@ -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/node/src/Tests/NodeBodyFieldStorageTest.php b/core/modules/node/src/Tests/NodeBodyFieldStorageTest.php
index ddf7559..2441a57 100644
--- a/core/modules/node/src/Tests/NodeBodyFieldStorageTest.php
+++ b/core/modules/node/src/Tests/NodeBodyFieldStorageTest.php
@@ -29,7 +29,6 @@ class NodeBodyFieldStorageTest extends KernelTestBase {
   protected function setUp() {
     parent::setUp();
     $this->installSchema('system', 'sequences');
-    $this->installSchema('system', array('router'));
     // Necessary for module uninstall.
     $this->installSchema('user', 'users_data');
     $this->installEntitySchema('user');
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..1d8cc0e 100644
--- a/core/modules/rest/src/Tests/RestLinkManagerTest.php
+++ b/core/modules/rest/src/Tests/RestLinkManagerTest.php
@@ -21,15 +21,6 @@ class RestLinkManagerTest extends KernelTestBase {
   public static $modules = ['rest', 'rest_test', 'system'];
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-    $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
-  }
-
-  /**
    * Tests that type hooks work as expected.
    */
   public function testRestLinkManagers() {
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..0bd5023 100644
--- a/core/modules/serialization/src/Tests/NormalizerTestBase.php
+++ b/core/modules/serialization/src/Tests/NormalizerTestBase.php
@@ -23,9 +23,8 @@ protected function setUp() {
 
     $this->installEntitySchema('entity_test_mulrev');
     $this->installEntitySchema('user');
-    $this->installSchema('system', array('url_alias', 'router'));
+    $this->installSchema('system', 'url_alias');
     $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/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php
index a1fb995..4d43d3a 100644
--- a/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php
+++ b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetTest.php
@@ -35,7 +35,6 @@ class MigrateShortcutSetTest extends MigrateDrupal7TestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', array('router'));
     $this->installEntitySchema('shortcut');
     $this->installEntitySchema('menu_link_content');
     $this->executeMigration('d7_shortcut_set');
diff --git a/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php
index c6d4530..18318ed 100644
--- a/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php
+++ b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutSetUsersTest.php
@@ -34,7 +34,6 @@ class MigrateShortcutSetUsersTest extends MigrateDrupal7TestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', array('router'));
     $this->installEntitySchema('shortcut');
     $this->installEntitySchema('menu_link_content');
     $this->installSchema('shortcut', ['shortcut_set_users']);
diff --git a/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php
index 8bf10ee..171bc38 100644
--- a/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php
+++ b/core/modules/shortcut/src/Tests/Migrate/d7/MigrateShortcutTest.php
@@ -35,7 +35,6 @@ class MigrateShortcutTest extends MigrateDrupal7TestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', array('router'));
     $this->installEntitySchema('shortcut');
     $this->installEntitySchema('menu_link_content');
     $this->executeMigration('d7_shortcut_set');
diff --git a/core/modules/simpletest/src/RouteBuilder.php b/core/modules/simpletest/src/RouteBuilder.php
new file mode 100644
index 0000000..3672af4
--- /dev/null
+++ b/core/modules/simpletest/src/RouteBuilder.php
@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\ProxyClass\Routing\RouteBuilder.
+ */
+
+namespace Drupal\simpletest;
+
+use Drupal\Core\DependencyInjection\DependencySerializationTrait;
+use Drupal\Core\DestructableInterface;
+use Drupal\Core\Routing\RouteBuilderInterface;
+
+/**
+ * Installs the router table on demand.
+ *
+ * @see \Drupal\Component\ProxyBuilder
+ */
+class RouteBuilder implements RouteBuilderInterface, DestructableInterface {
+
+  use DependencySerializationTrait;
+
+  /**
+   * @var bool
+   */
+  protected $tableInstalled;
+
+  /**
+   * Loads the router builder and installs the router table.
+   *
+   * @param bool $table_needed
+   *   TRUE when the table needs to be installed.
+   *
+   * @return \Drupal\Core\Routing\RouteBuilderInterface|\Drupal\Core\DestructableInterface
+   *   Returns the real route builder.
+   */
+  protected function lazyLoadItself($table_needed = FALSE) {
+    if (!isset($this->service)) {
+      $container = \Drupal::getContainer();
+      $this->service = $container->get('simpletest.router.builder');
+    }
+    if ($table_needed && !$this->tableInstalled) {
+      $container = \Drupal::getContainer();
+      $schema = $container->get('database')->schema();
+      if (!$schema->tableExists('router')) {
+        include_once $container->get('app.root') . '/core/modules/system/system.install';
+        $schema->createTable('router', system_schema()['router']);
+        $this->tableInstalled = TRUE;
+      }
+    }
+    return $this->service;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setRebuildNeeded() {
+    return $this->lazyLoadItself()->setRebuildNeeded();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function rebuild() {
+    return $this->lazyLoadItself(TRUE)->rebuild();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function rebuildIfNeeded() {
+    return $this->lazyLoadItself()->rebuildIfNeeded();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function destruct() {
+    return $this->lazyLoadItself()->destruct();
+  }
+
+}
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..9f16419 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,19 @@ 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.
+      foreach (['router.route_provider' => 'RouteProvider', 'router.builder' => 'RouteBuilder'] as $original_id => $class) {
+        for ($id = $original_id; $container->hasAlias($id); $id = (string) $container->getAlias($id));
+        $container->setDefinition("simpletest.$original_id", $container->getDefinition($id));
+        $container->setDefinition($id, new Definition('Drupal\simpletest\\' . $class));
+      }
+    }
+  }
 }
diff --git a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
index e10a6af..6e7290c 100644
--- a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
+++ b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
@@ -85,7 +85,6 @@ protected function setUp() {
     parent::setUp();
     $this->installSchema('system', 'sequences');
     $this->installEntitySchema('user');
-    $this->installSchema('system', array('router'));
     $this->installEntitySchema('menu_link_content');
 
     $account = User::create([
diff --git a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
index 7440d99..dc967e9 100644
--- a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
+++ b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
@@ -51,9 +51,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..e03febf 100644
--- a/core/modules/system/src/Tests/Common/PageRenderTest.php
+++ b/core/modules/system/src/Tests/Common/PageRenderTest.php
@@ -21,9 +21,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');
   }
 
@@ -32,9 +29,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..4b9db14 100644
--- a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
+++ b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
@@ -28,8 +28,6 @@ class RenderElementTypesTest extends KernelTestBase {
   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/Condition/CurrentThemeConditionTest.php b/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php
index 3139ecc..2f172a0 100644
--- a/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php
+++ b/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php
@@ -23,14 +23,6 @@ class CurrentThemeConditionTest extends KernelTestBase {
   public static $modules = array('system', 'theme_test');
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-    $this->installSchema('system', array('router'));
-  }
-
-  /**
    * Tests the current theme condition.
    */
   public function testCurrentTheme() {
diff --git a/core/modules/system/src/Tests/Element/PathElementFormTest.php b/core/modules/system/src/Tests/Element/PathElementFormTest.php
index bcbe534..d9ad44e 100644
--- a/core/modules/system/src/Tests/Element/PathElementFormTest.php
+++ b/core/modules/system/src/Tests/Element/PathElementFormTest.php
@@ -42,9 +42,8 @@ class PathElementFormTest extends KernelTestBase implements FormInterface {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', ['router', 'sequences', 'key_value_expire']);
+    $this->installSchema('system', ['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..02ff6e8 100644
--- a/core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php
+++ b/core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php
@@ -50,8 +50,7 @@ class EntityAutocompleteElementFormTest extends EntityUnitTestBase implements Fo
   protected function setUp() {
     parent::setUp();
 
-    $this->installSchema('system', ['router', 'key_value_expire']);
-    \Drupal::service('router.builder')->rebuild();
+    $this->installSchema('system', ['key_value_expire']);
 
     $this->testUser = User::create(array(
       'name' => 'foobar1',
diff --git a/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php b/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php
index f1385ca..006c5e2 100644
--- a/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityBundleFieldTest.php
@@ -41,7 +41,6 @@ class EntityBundleFieldTest extends EntityUnitTestBase  {
   protected function setUp() {
     parent::setUp();
     $this->installSchema('user', array('users_data'));
-    $this->installSchema('system', array('router'));
     $this->moduleHandler = $this->container->get('module_handler');
     $this->database = $this->container->get('database');
   }
diff --git a/core/modules/system/src/Tests/Entity/EntitySchemaTest.php b/core/modules/system/src/Tests/Entity/EntitySchemaTest.php
index 47b10ba..d86e71d 100644
--- a/core/modules/system/src/Tests/Entity/EntitySchemaTest.php
+++ b/core/modules/system/src/Tests/Entity/EntitySchemaTest.php
@@ -29,7 +29,6 @@ class EntitySchemaTest extends EntityUnitTestBase  {
   public function setUp() {
     parent::setUp();
     $this->installSchema('user', array('users_data'));
-    $this->installSchema('system', array('router'));
     $this->database = $this->container->get('database');
   }
 
diff --git a/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php b/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
index 4f223e3..9df409b 100644
--- a/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
+++ b/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
@@ -29,8 +29,7 @@ class FieldWidgetConstraintValidatorTest extends KernelTestBase {
   protected function setUp() {
     parent::setUp();
 
-    $this->installSchema('system', ['router', 'key_value']);
-    $this->container->get('router.builder')->rebuild();
+    $this->installSchema('system', 'key_value');
 
     $this->installEntitySchema('user');
     $this->installEntitySchema('entity_test_composite_constraint');
diff --git a/core/modules/system/src/Tests/File/StreamWrapperTest.php b/core/modules/system/src/Tests/File/StreamWrapperTest.php
index 343cd83..5816861 100644
--- a/core/modules/system/src/Tests/File/StreamWrapperTest.php
+++ b/core/modules/system/src/Tests/File/StreamWrapperTest.php
@@ -102,7 +102,6 @@ function testUriFunctions() {
     // Test file_create_url()
     // TemporaryStream::getExternalUrl() uses Url::fromRoute(), which needs
     // route information to work.
-    $this->installSchema('system', 'router');
     $this->container->get('router.builder')->rebuild();
     $this->assertTrue(strpos(file_create_url('temporary://test.txt'), 'system/temporary?file=test.txt'), 'Temporary external URL correctly built.');
     $this->assertTrue(strpos(file_create_url('public://test.txt'), Settings::get('file_public_path') . '/test.txt'), 'Public external URL correctly built.');
diff --git a/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php b/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php
index 3096310..171a4f4 100644
--- a/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php
+++ b/core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php
@@ -27,16 +27,6 @@ class StackKernelIntegrationTest extends KernelTestBase {
   public static $modules = array('httpkernel_test', 'system');
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
-  }
-
-  /**
    * Tests a request.
    */
   public function testRequest() {
diff --git a/core/modules/system/src/Tests/Menu/MenuLinkDefaultIntegrationTest.php b/core/modules/system/src/Tests/Menu/MenuLinkDefaultIntegrationTest.php
index 6078875..d96b29c 100644
--- a/core/modules/system/src/Tests/Menu/MenuLinkDefaultIntegrationTest.php
+++ b/core/modules/system/src/Tests/Menu/MenuLinkDefaultIntegrationTest.php
@@ -28,14 +28,6 @@ class MenuLinkDefaultIntegrationTest extends KernelTestBase {
   );
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-    $this->installSchema('system', array('router'));
-  }
-
-  /**
    * Tests moving a static menu link without a specified menu to the root.
    */
   public function testMoveToRoot() {
diff --git a/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php b/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php
index 011b58f..2117be8 100644
--- a/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php
+++ b/core/modules/system/src/Tests/Menu/MenuLinkTreeTest.php
@@ -53,7 +53,6 @@ class MenuLinkTreeTest extends KernelTestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', array('router'));
     $this->installEntitySchema('menu_link_content');
 
     $this->linkTree = $this->container->get('menu.link_tree');
diff --git a/core/modules/system/src/Tests/Render/Element/TableTest.php b/core/modules/system/src/Tests/Render/Element/TableTest.php
index 725f339..bb2b775 100644
--- a/core/modules/system/src/Tests/Render/Element/TableTest.php
+++ b/core/modules/system/src/Tests/Render/Element/TableTest.php
@@ -24,16 +24,6 @@ class TableTest extends KernelTestBase {
   public static $modules = ['system', 'form_test'];
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->installSchema('system', 'router');
-    \Drupal::service('router.builder')->rebuild();
-  }
-
-  /**
    * Tableheader.js provides 'sticky' table headers, and is included by default.
    */
   function testThemeTableStickyHeaders() {
diff --git a/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php b/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php
index 551e4d8..6b1da79 100644
--- a/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php
+++ b/core/modules/system/src/Tests/RouteProcessor/RouteNoneTest.php
@@ -41,10 +41,6 @@ class RouteNoneTest extends KernelTestBase {
    */
   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..200a7f5 100644
--- a/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php
+++ b/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php
@@ -40,10 +40,6 @@ class RouteProcessorCurrentIntegrationTest extends KernelTestBase {
    */
   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..dca17b5 100644
--- a/core/modules/system/src/Tests/Routing/ContentNegotiationRoutingTest.php
+++ b/core/modules/system/src/Tests/Routing/ContentNegotiationRoutingTest.php
@@ -31,8 +31,7 @@ protected function setUp() {
     \Drupal::unsetContainer();
     parent::setUp();
 
-    $this->installSchema('system', ['router', 'url_alias']);
-    \Drupal::service('router.builder')->rebuild();
+    $this->installSchema('system', 'url_alias');
   }
 
   /**
@@ -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..7b0f6cc 100644
--- a/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php
+++ b/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php
@@ -25,16 +25,6 @@ class ExceptionHandlingTest extends KernelTestBase {
   public static $modules = ['system', 'router_test'];
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
-  }
-
-  /**
    * Tests the exception handling for json and 403 status code.
    */
   public function testJson403() {
diff --git a/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php b/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php
index 66239c9..40035d1 100644
--- a/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php
+++ b/core/modules/system/src/Tests/Routing/UrlIntegrationTest.php
@@ -27,19 +27,9 @@ class UrlIntegrationTest extends KernelTestBase {
   public static $modules = array('user', 'router_test', 'system');
 
   /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->installSchema('system', ['router']);
-  }
-
-  /**
    * 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..a8cd490 100644
--- a/core/modules/system/src/Tests/System/TokenReplaceUnitTestBase.php
+++ b/core/modules/system/src/Tests/System/TokenReplaceUnitTestBase.php
@@ -39,9 +39,6 @@ protected function setUp() {
     parent::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..73f8be0 100644
--- a/core/modules/system/src/Tests/System/TrustedHostsTest.php
+++ b/core/modules/system/src/Tests/System/TrustedHostsTest.php
@@ -85,7 +85,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/system/src/Tests/Theme/TwigWhiteListTest.php b/core/modules/system/src/Tests/Theme/TwigWhiteListTest.php
index 99612c2..f378940 100644
--- a/core/modules/system/src/Tests/Theme/TwigWhiteListTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigWhiteListTest.php
@@ -46,7 +46,7 @@ class TwigWhiteListTest extends KernelTestBase {
    */
   protected function setUp() {
     parent::setUp();
-    $this->installSchema('system', array('router', 'sequences'));
+    $this->installSchema('system', 'sequences');
     $this->installEntitySchema('node');
     $this->installEntitySchema('user');
     $this->installEntitySchema('taxonomy_term');
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..e1cc2dd 100644
--- a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
+++ b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php
@@ -78,10 +78,6 @@ function testUserEditForm() {
     // Install default configuration; required for AccountFormController.
     $this->installConfig(array('user'));
 
-    // Install the router table and then rebuild.
-    $this->installSchema('system', ['router']);
-    \Drupal::service('router.builder')->rebuild();
-
     $form = $this->buildAccountForm('default');
 
     // Verify name and pass field order.
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..0d53cd0 100644
--- a/core/modules/views/src/Tests/ViewKernelTestBase.php
+++ b/core/modules/views/src/Tests/ViewKernelTestBase.php
@@ -42,11 +42,11 @@
   protected function setUp($import_test_views = TRUE) {
     parent::setUp();
 
-    $this->installSchema('system', array('router', 'sequences'));
+    $this->installSchema('system', 'sequences');
     $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();
+    }
   }
 
   /**
