diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php b/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php
index 53c1745a80..ae82624360 100644
--- a/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php
+++ b/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php
@@ -73,7 +73,7 @@ public function testOverviewPage() {
     $this->assertEquals($feed->label(), $link[0]->getText());
     $count = $this->container->get('entity_type.manager')->getStorage('aggregator_item')->getItemCount($feed);
     $td = $this->xpath('//table/tbody/tr//td[2]');
-    $this->assertEquals(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), $td[0]->getText());
+    $this->assertEquals(static::castSafeStrings(\Drupal::translation()->formatPlural($count, '1 item', '@count items')), $td[0]->getText());
 
     // Update the items of the first feed.
     $feed->refreshItems();
@@ -84,7 +84,7 @@ public function testOverviewPage() {
     $this->assertEquals($feed->label(), $link[0]->getText());
     $count = $this->container->get('entity_type.manager')->getStorage('aggregator_item')->getItemCount($feed);
     $td = $this->xpath('//table/tbody/tr//td[2]');
-    $this->assertEquals(\Drupal::translation()->formatPlural($count, '1 item', '@count items'), $td[0]->getText());
+    $this->assertEquals(static::castSafeStrings(\Drupal::translation()->formatPlural($count, '1 item', '@count items')), $td[0]->getText());
   }
 
 }
diff --git a/core/modules/aggregator/tests/src/Kernel/FeedValidationTest.php b/core/modules/aggregator/tests/src/Kernel/FeedValidationTest.php
index d8804dd9c3..d9409f81c5 100644
--- a/core/modules/aggregator/tests/src/Kernel/FeedValidationTest.php
+++ b/core/modules/aggregator/tests/src/Kernel/FeedValidationTest.php
@@ -55,13 +55,13 @@ public function testValidation() {
 
     $this->assertEqual(count($violations), 2);
     $this->assertEqual($violations[0]->getPropertyPath(), 'title');
-    $this->assertEqual($violations[0]->getMessage(), t('A feed named %value already exists. Enter a unique title.', [
+    $this->assertEqual($violations[0]->getMessage(), static::castSafeStrings(t('A feed named %value already exists. Enter a unique title.', [
       '%value' => $feed->label(),
-    ]));
+    ])));
     $this->assertEqual($violations[1]->getPropertyPath(), 'url');
-    $this->assertEqual($violations[1]->getMessage(), t('A feed with this URL %value already exists. Enter a unique URL.', [
+    $this->assertEqual($violations[1]->getMessage(), static::castSafeStrings(t('A feed with this URL %value already exists. Enter a unique URL.', [
       '%value' => $feed->getUrl(),
-    ]));
+    ])));
   }
 
 }
diff --git a/core/modules/aggregator/tests/src/Kernel/Views/IntegrationTest.php b/core/modules/aggregator/tests/src/Kernel/Views/IntegrationTest.php
index 7459cee66d..edcc5f5756 100644
--- a/core/modules/aggregator/tests/src/Kernel/Views/IntegrationTest.php
+++ b/core/modules/aggregator/tests/src/Kernel/Views/IntegrationTest.php
@@ -116,19 +116,19 @@ public function testAggregatorItemView() {
       $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $row) {
         return $view->field['title']->advancedRender($row);
       });
-      $this->assertEqual($output, $expected_link->getGeneratedLink(), 'Ensure the right link is generated');
+      $this->assertEqual(static::castSafeStrings($output), $expected_link->getGeneratedLink(), 'Ensure the right link is generated');
 
       $expected_author = Xss::filter($items[$iid]->getAuthor(), _aggregator_allowed_tags());
       $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $row) {
         return $view->field['author']->advancedRender($row);
       });
-      $this->assertEqual($output, $expected_author, 'Ensure the author got filtered');
+      $this->assertEqual(static::castSafeStrings($output), $expected_author, 'Ensure the author got filtered');
 
       $expected_description = Xss::filter($items[$iid]->getDescription(), _aggregator_allowed_tags());
       $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $row) {
         return $view->field['description']->advancedRender($row);
       });
-      $this->assertEqual($output, $expected_description, 'Ensure the author got filtered');
+      $this->assertEqual(static::castSafeStrings($output), $expected_description, 'Ensure the author got filtered');
     }
   }
 
diff --git a/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php b/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php
index e5a2bd95da..643ff1b6cd 100644
--- a/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php
@@ -55,9 +55,9 @@ public function testGetDerivativeDefinitions() {
         'action_label' => 'Delete',
         'confirm_form_route_name' => 'entity.entity_test_rev.delete_multiple_form',
       ],
-    ], $deriver->getDerivativeDefinitions([
+    ], static::castSafeStrings($deriver->getDerivativeDefinitions([
       'action_label' => 'Delete',
-    ]));
+    ])));
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index fd26d08a14..2383477fea 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -1103,8 +1103,8 @@ public static function assertEquals($expected, $actual, $message = '', $delta =
     // Cast objects implementing MarkupInterface to string instead of
     // relying on PHP casting them to string depending on what they are being
     // comparing with.
-    $expected = static::castSafeStrings($expected);
-    $actual = static::castSafeStrings($actual);
+    $expected = static::castSafeStrings($expected, TRUE);
+    $actual = static::castSafeStrings($actual, TRUE);
     parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
   }
 
diff --git a/core/tests/Drupal/Tests/AssertHelperTrait.php b/core/tests/Drupal/Tests/AssertHelperTrait.php
index ba814d9641..44c59ab198 100644
--- a/core/tests/Drupal/Tests/AssertHelperTrait.php
+++ b/core/tests/Drupal/Tests/AssertHelperTrait.php
@@ -14,17 +14,26 @@
    *
    * @param string|array $value
    *   The value to act on.
+   * @param bool $is_deprecated
+   *   (Optional) If TRUE and a value is cast to string, throws a deprecation
+   *   error. Defaults to FALSE.
    *
    * @return mixed
    *   The input value, with MarkupInterface objects casted to string.
    */
-  protected static function castSafeStrings($value) {
+  protected static function castSafeStrings($value, $is_deprecated = FALSE) {
     if ($value instanceof MarkupInterface) {
+      if ($is_deprecated) {
+        @trigger_error('Support for automatic casting MarkupInterface objects into strings in ::assertEquals is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Do xxx instead. See https://www.drupal.org/node/xxx', E_USER_DEPRECATED);
+      }
       $value = (string) $value;
     }
     if (is_array($value)) {
-      array_walk_recursive($value, function (&$item) {
+      array_walk_recursive($value, function (&$item, $is_deprecated) {
         if ($item instanceof MarkupInterface) {
+          if ($is_deprecated) {
+            @trigger_error('Support for automatic casting MarkupInterface objects into strings in ::assertEquals is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Do xxx instead. See https://www.drupal.org/node/xxx', E_USER_DEPRECATED);
+          }
           $item = (string) $item;
         }
       });
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index 2b1ee867b1..21f8e36012 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -685,8 +685,8 @@ public static function assertEquals($expected, $actual, $message = '', $delta =
     // Cast objects implementing MarkupInterface to string instead of
     // relying on PHP casting them to string depending on what they are being
     // comparing with.
-    $expected = static::castSafeStrings($expected);
-    $actual = static::castSafeStrings($actual);
+    $expected = static::castSafeStrings($expected, TRUE);
+    $actual = static::castSafeStrings($actual, TRUE);
     parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
   }
 
