diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 35af531737a799eee9c78770cb1edc46a83dea8f..a67d0912a96144ca22959aa62b130b5238ced479 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -867,6 +867,9 @@ protected function prepareEnvironment() {
 
     // Ensure that the current session is not changed by the new environment.
     drupal_save_session(FALSE);
+    // Run all tests as a anonymous user by default, web tests will replace that
+    // during the test set up.
+    $user = drupal_anonymous_user();
 
     // Save and clean the shutdown callbacks array because it is static cached
     // and will be changed by the test run. Otherwise it will contain callbacks
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 4e7b6b1d4893d0bd1453d869c071fcc2e05bbf8a..7b50b10ff6de60486b50306ec12ea9ebe7bc5039 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -775,10 +775,6 @@ protected function setUp() {
       ),
     );
 
-    // Replace the global $user session with an anonymous user to resemble a
-    // regular installation.
-    $user = drupal_anonymous_user();
-
     // Reset the static batch to remove Simpletest's batch operations.
     $batch = &batch_get();
     $batch = array();