diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php
index 988a40bb16be714ee7a91cdfe7c5e9a7c0368bfd..a646096d1dabd0c89b390c016d81bfa902ddced1 100644
--- a/core/lib/Drupal.php
+++ b/core/lib/Drupal.php
@@ -102,9 +102,11 @@ class Drupal {
    * Sets a new global container.
    *
    * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
-   *   A new container instance to replace the current.
+   *   A new container instance to replace the current. NULL may be passed by
+   *   testing frameworks to ensure that the global state of a previous
+   *   environment does not leak into a test.
    */
-  public static function setContainer(ContainerInterface $container) {
+  public static function setContainer(ContainerInterface $container = NULL) {
     static::$container = $container;
   }
 
diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php
index ca0968d62e5480c68b0ab3bb932f5d7f7feec295..b862f12a0672ba65927df78ab0983f16e35ffba3 100644
--- a/core/tests/Drupal/Tests/UnitTestCase.php
+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -48,12 +48,11 @@ public static function getInfo() {
   /**
    * {@inheritdoc}
    */
-  protected function tearDown() {
-    parent::tearDown();
-    if (\Drupal::getContainer()) {
-      $container = new ContainerBuilder();
-      \Drupal::setContainer($container);
-    }
+  protected function setUp() {
+    parent::setUp();
+    // Ensure that an instantiated container in the global state of \Drupal from
+    // a previous test does not leak into this test.
+    \Drupal::setContainer(NULL);
   }
 
   /**