diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php
index a29db8c..d1cd0c0 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php
@@ -72,7 +72,7 @@ function testCommentEnable() {
     $edit = array();
     $edit['modules[Core][comment][enable]'] = FALSE;
     $this->drupalPost('admin/modules', $edit, t('Save configuration'));
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->assertFalse(module_exists('comment'), 'Comment module disabled.');
 
     // Enable core content type module (book).
@@ -84,7 +84,7 @@ function testCommentEnable() {
     $edit = array();
     $edit['modules[Core][comment][enable]'] = 'comment';
     $this->drupalPost('admin/modules', $edit, t('Save configuration'));
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->assertTrue(module_exists('comment'), 'Comment module enabled.');
 
     // Create nodes of each type.
diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditorAdminTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditorAdminTest.php
index 783fdd9..7cafb9e 100644
--- a/core/modules/editor/lib/Drupal/editor/Tests/EditorAdminTest.php
+++ b/core/modules/editor/lib/Drupal/editor/Tests/EditorAdminTest.php
@@ -67,7 +67,6 @@ function testWithoutEditorAvailable() {
 
     // Make a text editor available.
     module_enable(array('editor_test'));
-    $this->rebuildContainer();
     $this->resetAll();
     $this->drupalGet('admin/config/content/formats/filtered_html');
 
diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php
index c08ce70..450b48c 100644
--- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php
+++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php
@@ -116,7 +116,7 @@ function testEnableForumField() {
     $edit['modules[Core][forum][enable]'] = FALSE;
     $this->drupalPost('admin/modules', $edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->assertFalse(module_exists('forum'), 'Forum module is not enabled.');
 
     // Attempt to re-enable the Forum module and ensure it does not try to
@@ -125,7 +125,7 @@ function testEnableForumField() {
     $edit['modules[Core][forum][enable]'] = 'forum';
     $this->drupalPost('admin/modules', $edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->assertTrue(module_exists('forum'), 'Forum module is enabled.');
   }
 
diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php
index ee2b0c3..a340475 100644
--- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php
+++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php
@@ -104,7 +104,7 @@ function testUninstallProcess() {
     // Uninstall Locale.
     module_disable($locale_module);
     module_uninstall($locale_module);
-    $this->rebuildContainer();
+    $this->resetAll();
 
     // Visit the front page.
     $this->drupalGet('');
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
index bc472c4..33714b1 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
@@ -95,10 +95,8 @@ protected function setUp() {
     state()->set('system.theme.files', $this->themeFiles);
     state()->set('system.theme.data', $this->themeData);
 
-    // Bootstrap the kernel.
-    // No need to dump it; this test runs in-memory.
-    $this->kernel = new DrupalKernel('unit_testing', TRUE, drupal_classloader(), FALSE);
-    $this->kernel->boot();
+    // Prepare the kernel.
+    $this->prepareKernel();
 
     // Collect and set a fixed module list.
     $class = get_class($this);
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 35af531..c96ec32 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -947,22 +947,12 @@ protected function prepareConfigDirectories() {
   }
 
   /**
-   * Rebuild drupal_container().
-   *
-   * Use this to build a new kernel and service container. For example, when the
-   * list of enabled modules is changed via the internal browser, in which case
-   * the test process still contains an old kernel and service container with an
-   * old module list.
-   *
-   * @todo Fix http://drupal.org/node/1708692 so that module enable/disable
-   *   changes are immediately reflected in drupal_container(). Until then,
-   *   tests can invoke this workaround when requiring services from newly
-   *   enabled modules to be immediately available in the same request.
+   * Prepares the DrupalKernel to use for the test.
    *
    * @see TestBase::prepareEnvironment()
    * @see TestBase::tearDown()
    */
-  protected function rebuildContainer() {
+  protected function prepareKernel() {
     $this->kernel = new DrupalKernel('testing', FALSE, drupal_classloader(), FALSE);
     $this->kernel->boot();
     // DrupalKernel replaces the container in drupal_container() with a
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 95c8254..0c62a81 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -797,10 +797,14 @@ protected function setUp() {
       }
     }
     $GLOBALS['conf']['file_public_path'] = $this->public_files_directory;
+
     // Execute the non-interactive installer.
     require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
     install_drupal($settings);
-    $this->rebuildContainer();
+
+    // The installer uses a 'install' kernel. Now that the installation is
+    // finished, prepare a 'testing' kernel.
+    $this->prepareKernel();
 
     // Restore the original Simpletest batch.
     $batch = &batch_get();
@@ -829,7 +833,6 @@ protected function setUp() {
       $modules = array_unique($modules);
       $success = module_enable($modules, TRUE);
       $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
-      $this->rebuildContainer();
     }
 
     // Reset/rebuild all data structures after enabling the modules.
@@ -870,6 +873,10 @@ protected function resetAll() {
     // Clear all database and static caches and rebuild data structures.
     drupal_flush_all_caches();
 
+    // When modules are enabled, the container in drupal_container() is replaced
+    // with a rebuilt object. Update the container used by tests to match.
+    $this->container = drupal_container();
+
     // Reload global $conf array and permissions.
     $this->refreshVariables();
     $this->checkPermissions(array(), TRUE);
diff --git a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php
index 7804b0a..3f12eff 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php
@@ -57,7 +57,7 @@ function assertTableCount($base_table, $count = TRUE) {
    *   The name of the module.
    */
   function assertModuleTablesExist($module) {
-    $this->rebuildContainer();
+    $this->resetAll();
     $tables = array_keys(drupal_get_schema_unprocessed($module));
     $tables_exist = TRUE;
     foreach ($tables as $table) {
@@ -145,7 +145,7 @@ function assertNoModuleConfig($module) {
    *   Expected module state.
    */
   function assertModules(array $modules, $enabled) {
-    $this->rebuildContainer();
+    $this->resetAll();
     foreach ($modules as $module) {
       if ($enabled) {
         $message = 'Module "@module" is enabled.';
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/MainContentFallbackTest.php b/core/modules/system/lib/Drupal/system/Tests/System/MainContentFallbackTest.php
index 4e79ae9..a484fd0 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/MainContentFallbackTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/MainContentFallbackTest.php
@@ -56,7 +56,7 @@ function testMainContentFallback() {
     $edit['modules[Core][block][enable]'] = FALSE;
     $this->drupalPost('admin/modules', $edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->assertFalse(module_exists('block'), 'Block module disabled.');
 
     // At this point, no region is filled and fallback should be triggered.
@@ -90,7 +90,7 @@ function testMainContentFallback() {
     $edit['modules[Core][block][enable]'] = 'block';
     $this->drupalPost('admin/modules', $edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->assertTrue(module_exists('block'), 'Block module re-enabled.');
   }
 }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
index 20ccc2b..b6f8dee 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
@@ -177,18 +177,12 @@ function testRegistryRebuild() {
     $this->assertIdentical(theme('theme_test_foo', array('foo' => 'a')), 'a', 'The theme registry contains theme_test_foo.');
 
     module_disable(array('theme_test'), FALSE);
-    // After enabling/disabling a module during a test, we need to rebuild the
-    // container and ensure the extension handler is loaded, otherwise theme()
-    // throws an exception.
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->container->get('module_handler')->loadAll();
     $this->assertIdentical(theme('theme_test_foo', array('foo' => 'b')), '', 'The theme registry does not contain theme_test_foo, because the module is disabled.');
 
     module_enable(array('theme_test'), FALSE);
-    // After enabling/disabling a module during a test, we need to rebuild the
-    // container and ensure the extension handler is loaded, otherwise theme()
-    // throws an exception.
-    $this->rebuildContainer();
+    $this->resetAll();
     $this->container->get('module_handler')->loadAll();
     $this->assertIdentical(theme('theme_test_foo', array('foo' => 'c')), 'c', 'The theme registry contains theme_test_foo again after re-enabling the module.');
   }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php
index 0bcd1a6..cfe29fa 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php
@@ -36,9 +36,8 @@ function testTwigDebugMarkup() {
     $extension = twig_extension();
     theme_enable(array('test_theme_twig'));
     config('system.theme')->set('default', 'test_theme_twig')->save();
-    // Enable debug, rebuild the service container, and clear all caches.
+    // Enable debug.
     $this->settingsSet('twig_debug', TRUE);
-    $this->rebuildContainer();
     $this->resetAll();
 
     $cache = array();
@@ -67,9 +66,8 @@ function testTwigDebugMarkup() {
     $this->assertTrue(strpos($output, '* node--2' . $extension) !== FALSE, 'Node ID specific template suggestion found.');
     $this->assertTrue(strpos($output, 'x node' . $extension) !== FALSE, 'Base template file shown as current template.');
 
-    // Disable debug, rebuild the service container, and clear all caches.
+    // Disable debug.
     $this->settingsSet('twig_debug', FALSE);
-    $this->rebuildContainer();
     $this->resetAll();
 
     $output = theme('node', node_view($node));
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
index 74c9923..3bfb44f 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
@@ -220,10 +220,11 @@ protected function performUpgrade($register_errors = TRUE) {
       throw new Exception('An error was encountered during the first access to update.php.');
     }
 
-    // Initialize config directories and rebuild the service container after
-    // creating them in the first step.
+    // Initialize config directories.
     parent::prepareConfigDirectories();
-    $this->rebuildContainer();
+
+    // Prepare the kernel.
+    $this->prepareKernel();
 
     // Continue.
     $this->drupalPost(NULL, array(), t('Continue'));
@@ -286,8 +287,7 @@ protected function performUpgrade($register_errors = TRUE) {
     drupal_container()->get('module_handler')->resetImplementations();
     drupal_container()->get('module_handler')->reload();
 
-    // Rebuild the container and all caches.
-    $this->rebuildContainer();
+    // Reset all caches.
     $this->resetAll();
 
     return TRUE;
@@ -303,7 +303,6 @@ protected function performUpgrade($register_errors = TRUE) {
    * @see WebTestBase::drupalGet()
    */
   protected function getUpdatePhp() {
-    $this->rebuildContainer();
     $path = $GLOBALS['base_url'] . '/core/update.php';
     $out = $this->curlExec(array(CURLOPT_HTTPGET => TRUE, CURLOPT_URL => $path, CURLOPT_NOBODY => FALSE));
     // Ensure that any changes to variables in the other thread are picked up.
