diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php
index 6fe62a1e562ad303df00bddf6a40b60445db145d..26ea046b3053a7054cfe2a427b45df2498b6a336 100644
--- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php
+++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php
@@ -7,8 +7,8 @@
 
 namespace Drupal\Tests\Core\Menu;
 
-use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Menu\LocalTaskDefault;
+use Drupal\Core\Routing\RouteProviderInterface;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
 use Symfony\Component\HttpFoundation\Request;
@@ -84,11 +84,11 @@ protected function setUp() {
    * Setups the local task default.
    */
   protected function setupLocalTaskDefault() {
-    $container = new ContainerBuilder();
-    $container->set('string_translation', $this->stringTranslation);
-    $container->set('router.route_provider', $this->routeProvider);
-    \Drupal::setContainer($container);
-    $this->localTaskBase = new LocalTaskDefault($this->config, $this->pluginId, $this->pluginDefinition);
+    $this->localTaskBase = new TestLocalTaskDefault($this->config, $this->pluginId, $this->pluginDefinition);
+    $this->localTaskBase
+      ->setRouteProvider($this->routeProvider)
+      ->setTranslationManager($this->stringTranslation);
+
   }
 
   /**
@@ -316,3 +316,10 @@ public function testGetOptions() {
   }
 
 }
+
+class TestLocalTaskDefault extends LocalTaskDefault {
+  public function setRouteProvider(RouteProviderInterface $route_provider) {
+    $this->routeProvider = $route_provider;
+    return $this;
+  }
+}