diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index c61015b..4e4972b 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -829,6 +829,35 @@ protected function prepareEnvironment() {
   }
 
   /**
+   * Rebuild drupal_container().
+   *
+   * @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.
+   */
+  protected function rebuildContainer() {
+    // DrupalKernel expects to merge a fresh bootstrap container, not remerge
+    // what is left over from a prior container build.
+    drupal_container(NULL, TRUE);
+    // Create a new DrupalKernel for testing purposes, now that all required
+    // modules have been enabled. This also stores a new dependency injection
+    // container in drupal_container(). Drupal\simpletest\TestBase::tearDown()
+    // restores the original container.
+    // @see Drupal\Core\DrupalKernel::initializeContainer()
+    $this->kernel = new DrupalKernel('testing', FALSE);
+    // Booting the kernel is necessary to initialize the new DIC. While
+    // normally the kernel gets booted on demand in
+    // Symfony\Component\HttpKernel\handle(), this kernel needs manual booting
+    // as it is not used to handle a request.
+    $this->kernel->boot();
+    // The DrupalKernel does not update the container in drupal_container(), but
+    // replaces it with a new object. We therefore need to replace the minimal
+    // boostrap container that has been set up by TestBase::prepareEnvironment().
+    $this->container = drupal_container();
+  }
+
+  /**
    * Deletes created files, database tables, and reverts all environment changes.
    *
    * This method needs to be invoked for both unit and integration tests.
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 24bf1f2..400d885 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -684,6 +684,7 @@ protected function setUp() {
     // Execute the non-interactive installer.
     require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
     install_drupal($settings);
+    $this->rebuildContainer();
 
     // Restore the original Simpletest batch.
     $batch = &batch_get();
@@ -716,24 +717,9 @@ protected function setUp() {
     if ($modules) {
       $success = module_enable($modules, TRUE);
       $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
+      $this->rebuildContainer();
     }
 
-    // Create a new DrupalKernel for testing purposes, now that all required
-    // modules have been enabled. This also stores a new dependency injection
-    // container in drupal_container(). Drupal\simpletest\TestBase::tearDown()
-    // restores the original container.
-    // @see Drupal\Core\DrupalKernel::initializeContainer()
-    $this->kernel = new DrupalKernel('testing', FALSE);
-    // Booting the kernel is necessary to initialize the new DIC. While
-    // normally the kernel gets booted on demand in
-    // Symfony\Component\HttpKernel\handle(), this kernel needs manual booting
-    // as it is not used to handle a request.
-    $this->kernel->boot();
-    // The DrupalKernel does not update the container in drupal_container(), but
-    // replaces it with a new object. We therefore need to replace the minimal
-    // boostrap container that has been set up by TestBase::prepareEnvironment().
-    $this->container = drupal_container();
-
     // Reset/rebuild all data structures after enabling the modules.
     $this->resetAll();
 
