diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 46fbcbc..891174e 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -2172,15 +2172,6 @@ function install_update_configuration_translations(&$install_state) {
  *   A message informing the user that the installation is complete.
  */
 function install_finished(&$install_state) {
-  $profile = drupal_get_profile();
-
-  // Installation profiles are always loaded last.
-  module_set_weight($profile, 1000);
-
-  // Flush all caches to ensure that any full bootstraps during the installer
-  // do not leave stale cached data, and that any content types or other items
-  // registered by the installation profile are registered correctly.
-  drupal_flush_all_caches();
 
   drupal_set_title(t('@drupal installation complete', array('@drupal' => drupal_install_profile_distribution_name())), PASS_THROUGH);
 
@@ -2225,6 +2216,10 @@ function _install_module_batch($module, $module_name, &$context) {
  * 'Finished' callback for module installation batch.
  */
 function _install_profile_modules_finished($success, $results, $operations) {
+  $profile = drupal_get_profile();
+  // Installation profiles are always loaded last.
+  module_set_weight($profile, 1000);
+
   // Flush all caches to complete the module installation process. Subsequent
   // installation tasks will now have full access to the profile's modules.
   drupal_flush_all_caches();
@@ -2722,6 +2717,8 @@ function install_configure_form_submit($form, &$form_state) {
     if ($form_state['values']['update_status_module'][2]) {
       \Drupal::config('update.settings')->set('notification.emails', array($form_state['values']['account']['mail']))->save();
     }
+    // Flush all caches after module installation.
+    drupal_flush_all_caches();
   }
 
   // We precreated user 1 with placeholder values. Let's save the real values.
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 265012e..418241c 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -823,16 +823,15 @@ protected function setUp() {
       }
       $class = get_parent_class($class);
     }
+
     if ($modules) {
       $modules = array_unique($modules);
       $success = \Drupal::moduleHandler()->install($modules, TRUE);
       $this->assertTrue($success, t('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
-      $this->rebuildContainer();
+      // Reset/rebuild all data structures after enabling the modules.
+      $this->resetAll();
     }
 
-    // Reset/rebuild all data structures after enabling the modules.
-    $this->resetAll();
-
     // Now make sure that the file path configurations are saved. This is done
     // after we install the modules to override default values.
     foreach ($variable_groups as $config_base => $variables) {
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
index b871710..d1fd5b1 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php
@@ -7,12 +7,15 @@
 
 namespace Drupal\system\Tests\Common;
 
-use Drupal\simpletest\WebTestBase;
+use Drupal\simpletest\DrupalUnitTestBase;
 
 /**
  * Tests drupal_add_feed().
  */
-class AddFeedTest extends WebTestBase {
+class AddFeedTest extends DrupalUnitTestBase {
+
+  public static $modules = array('system');
+
   public static function getInfo() {
     return array(
       'name' => 'drupal_add_feed() tests',
@@ -70,15 +73,15 @@ function testBasicFeedAddNoTitle() {
       ),
     );
 
-    foreach ($urls as $description => $feed_info) {
+    foreach ($urls as $feed_info) {
       $build['#attached']['drupal_add_feed'][] = array($feed_info['input_url'], $feed_info['title']);
     }
 
     drupal_render($build);
 
-    $this->drupalSetContent(drupal_get_html_head());
+    $content = drupal_get_html_head();
     foreach ($urls as $description => $feed_info) {
-      $this->assertPattern($this->urlToRSSLinkPattern($feed_info['output_url'], $feed_info['title']), format_string('Found correct feed header for %description', array('%description' => $description)));
+      $this->assertTrue((bool) preg_match($this->urlToRSSLinkPattern($feed_info['output_url'], $feed_info['title']), $content), format_string('Found correct feed header for %description', array('%description' => $description)));
     }
   }
 
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php
index 9ba4bf4..8bf96fd 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php
@@ -7,12 +7,15 @@
 
 namespace Drupal\system\Tests\Common;
 
-use Drupal\simpletest\WebTestBase;
+use Drupal\simpletest\DrupalUnitTestBase;
 
 /**
  * Tests the markup of core render element types passed to drupal_render().
  */
-class RenderElementTypesTest extends WebTestBase {
+class RenderElementTypesTest extends DrupalUnitTestBase {
+
+  public static $modules = array('system');
+
   public static function getInfo() {
     return array(
       'name' => 'Render element types',
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php
index 4344801..1782281 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php
@@ -22,6 +22,11 @@ public static function getInfo() {
     );
   }
 
+  public function setUp() {
+    parent::setUp();
+    $this->resetAll();
+  }
+
   /**
    * Creates a user and a node, then tests the tokens generated from them.
    */
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php
index 1a9d3d1..55d6280 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TableTest.php
@@ -7,12 +7,15 @@
 
 namespace Drupal\system\Tests\Theme;
 
-use Drupal\simpletest\WebTestBase;
+use Drupal\simpletest\DrupalUnitTestBase;
 
 /**
  * Unit tests for theme_table().
  */
-class TableTest extends WebTestBase {
+class TableTest extends DrupalUnitTestBase {
+
+  public static $modules = array('system');
+
   public static function getInfo() {
     return array(
       'name' => 'Theme Table',
@@ -81,4 +84,44 @@ function testThemeTableWithNoStriping() {
     $this->assertNoRaw('class="odd"', 'Odd/even classes were not added because $no_striping = TRUE.');
     $this->assertNoRaw('no_striping', 'No invalid no_striping HTML attribute was printed.');
   }
+
+  /**
+   * Passes if the raw text IS found on the loaded page, fail otherwise.
+   *
+   * Raw text refers to the raw HTML that the page generated.
+   *
+   * @param $raw
+   *   Raw (HTML) string to look for.
+   *
+   * @return
+   *   TRUE on pass, FALSE on fail.
+   */
+  protected function assertRaw($raw, $message = '') {
+    if (!$message) {
+      $message = t('Raw "@raw" found', array('@raw' => $raw));
+    }
+    return $this->assert(strpos($this->content, $raw) !== FALSE, $message);
+  }
+
+  /**
+   * Passes if the raw text is NOT found on the loaded page, fail otherwise.
+   *
+   * Raw text refers to the raw HTML that the page generated.
+   *
+   * @param $raw
+   *   Raw (HTML) string to look for.
+   * @param $message
+   *   (optional) A message to display with the assertion. Do not translate
+   *   messages: use format_string() to embed variables in the message text, not
+   *   t(). If left blank, a default message will be displayed.
+   *
+   * @return
+   *   TRUE on pass, FALSE on fail.
+   */
+  protected function assertNoRaw($raw, $message = '') {
+    if (!$message) {
+      $message = t('Raw "@raw" not found', array('@raw' => $raw));
+    }
+    return $this->assert(strpos($this->content, $raw) === FALSE, $message);
+  }
 }
