diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
index 54305c0..c76ff81 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
@@ -88,7 +88,7 @@ protected function setUp() {
 
     parent::setUp();
     // Build a minimal, partially mocked environment for unit tests.
-    $this->containerBuild(drupal_container());
+    $this->containerBuild($this->container);
     // Make sure it survives kernel rebuilds.
     $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\simpletest\TestServiceProvider';
 
@@ -156,7 +156,7 @@ public function containerBuild(ContainerBuilder $container) {
     $container->set('keyvalue.memory', $this->keyValueFactory);
     if (!$container->has('keyvalue')) {
       // TestBase::setUp puts a completely empty container in
-      // drupal_container() which is somewhat the mirror of the empty
+      //$this->container  which is somewhat the mirror of the empty
       // environment being set up. Unit tests need not to waste time with
       // getting a container set up for them. Drupal Unit Tests might just get
       // away with a simple container holding the absolute bare minimum. When
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 4040625..99a745f 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -879,7 +879,7 @@ protected function prepareEnvironment() {
     $this->originalConf = $conf;
 
     // Backup statics and globals.
-    $this->originalContainer = clone drupal_container();
+    $this->originalContainer = clone $this->container;
     $this->originalLanguage = $language_interface;
     $this->originalConfigDirectories = $GLOBALS['config_directories'];
     if (isset($GLOBALS['theme_key'])) {
@@ -1046,7 +1046,7 @@ protected function tearDown() {
     // In case a fatal error occurred that was not in the test process read the
     // log to pick up any fatal errors.
     simpletest_log_read($this->testId, $this->databasePrefix, get_class($this), TRUE);
-    if (($container = drupal_container()) && $container->has('keyvalue')) {
+    if (($container = $this->container) && $container->has('keyvalue')) {
       $captured_emails = \Drupal::state()->get('system.test_email_collector') ?: array();
       $emailCount = count($captured_emails);
       if ($emailCount) {
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index ab24fc8..97865d0 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -256,7 +256,7 @@ protected function drupalCreateNode(array $settings = array()) {
     );
 
     // Add in comment settings for nodes.
-    if (module_exists('comment')) {
+    if (\Drupal::moduleHandler()->moduleExists('comment')) {
       $settings += array(
         'comment' => COMMENT_NODE_OPEN,
       );
@@ -951,7 +951,7 @@ protected function refreshVariables() {
     $conf = variable_initialize();
     // Clear the tag cache.
     drupal_static_reset('Drupal\Core\Cache\CacheBackendInterface::tagCache');
-    drupal_container()->get('config.factory')->reset();
+    \Drupal::service('config.factory')->reset();
   }
 
   /**
