diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index dfb61e1..e934b20 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -3100,15 +3100,29 @@ function ip_address() {
  * are DRUPAL_ROOT and variable_get(). Otherwise it may be called as early as
  * possible.
  *
+ * @param $new_loader
+ *   (optional) Internal use only. A new class loader instance to replace the
+ *   current.
+ * @param bool $rebuild
+ *   (optional) Internal use only. Whether to reset the statically cached class
+ *   loader. Used by the testing framework to prevent the class loader from the
+ *   parent site (test runner) leaking into tests.
+ *
  * @return Symfony\Component\ClassLoader\UniversalClassLoader
  *   A UniversalClassLoader class instance (or extension thereof).
  */
-function drupal_classloader() {
+function drupal_classloader($new_loader = NULL, $rebuild = FALSE) {
   // By default, use the UniversalClassLoader which is best for development,
   // as it does not break when code is moved on the file system. However, as it
   // is slow, allow to use the APC class loader in production.
   static $loader;
 
+  if ($rebuild) {
+    $loader = NULL;
+  }
+  if (isset($new_loader)) {
+    $loader = $new_loader;
+  }
   if (!isset($loader)) {
     // Include the Symfony ClassLoader for loading PSR-0-compatible classes.
     require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 9d151e0..a5535e6 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -814,6 +814,7 @@ protected function prepareEnvironment() {
     $this->originalConf = $conf;
 
     // Backup statics and globals.
+    $this->originalClassLoader = clone drupal_classloader();
     $this->originalContainer = clone drupal_container();
     $this->originalLanguage = $language_interface;
     $this->originalConfigDirectories = $GLOBALS['config_directories'];
@@ -851,6 +852,13 @@ protected function prepareEnvironment() {
     file_prepare_directory($this->translation_files_directory, FILE_CREATE_DIRECTORY);
     $this->generatedTestFiles = FALSE;
 
+    // Unregister the classloader and register a freshly built one to ensure
+    // that registered namespaces of the test runner do not leak into the test.
+    // @todo Replace with ::unregister() when using ClassLoader.
+    // @see http://drupal.org/node/1658720
+    spl_autoload_unregister(array(drupal_classloader(), 'loadClass'));
+    drupal_classloader(NULL, TRUE);
+
     // Create and set new configuration directories. The child site
     // uses drupal_valid_test_ua() to adjust the config directory paths to
     // a test-prefix-specific directory within the public files directory.
@@ -1001,6 +1009,8 @@ protected function tearDown() {
     $conf = $this->originalConf;
 
     // Restore original statics and globals.
+    drupal_classloader($this->originalClassLoader);
+    $this->originalClassLoader->register();
     drupal_container($this->originalContainer);
     $GLOBALS['config_directories'] = $this->originalConfigDirectories;
     if (isset($this->originalPrefix)) {
