diff --git a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
index d7bd225..3fec390 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/UnitTestBase.php
@@ -25,6 +25,13 @@
  protected $configDirectories;
 
   /**
+   * Temporary storage for the global user object.
+   *
+   * @var object
+   */
+  protected $user;
+
+  /**
    * Constructor for UnitTestBase.
    */
   function __construct($test_id = NULL) {
@@ -72,4 +79,21 @@ protected function setUp() {
 
     $this->setup = TRUE;
   }
+
+  /**
+   * Overrides \Drupal\simpletest\TestBase::run().
+   *
+   * This unsets the global user so that it does not cause inconsistent test
+   * results between browser runs and run-tests.sh runs. It then resets the
+   * global user so that (during browser runs) other systems such as Batch API
+   * have access to the uid.
+   */
+  public function run(array $methods = array()) {
+    $this->user = $GLOBALS['user'];
+    unset($GLOBALS['user']);
+
+    parent::run($methods);
+
+    $GLOBALS['user'] = $this->user;
+  }
 }
