diff --git a/core/modules/block/tests/src/Kernel/BlockInterfaceTest.php b/core/modules/block/tests/src/Kernel/BlockInterfaceTest.php
index 6e1a4d25451000bab8e7ca92f7886e6fc160ced4..b917d7184234b4931698c1921260607b70032b45 100644
--- a/core/modules/block/tests/src/Kernel/BlockInterfaceTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockInterfaceTest.php
@@ -87,7 +87,7 @@ public function testBlockInterface() {
     $actual_form = $display_block->buildConfigurationForm([], $form_state);
     // Remove the visibility sections, as that just tests condition plugins.
     unset($actual_form['visibility'], $actual_form['visibility_tabs']);
-    $this->assertIdentical($this->castSafeStrings($actual_form), $this->castSafeStrings($expected_form), 'Only the expected form elements were present.');
+    $this->assertEquals($expected_form, $actual_form, 'Only the expected form elements were present.');
 
     $expected_build = [
       '#children' => 'My custom display message.',
diff --git a/core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php b/core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
index 4868c76fdcd995f34454fc711567764e6132a739..bca2e9a3501c32abc006542c5dd12d4b92d20a46 100644
--- a/core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
+++ b/core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\book\Unit;
 
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -11,8 +10,6 @@
  */
 class BookUninstallValidatorTest extends UnitTestCase {
 
-  use AssertHelperTrait;
-
   /**
    * @var \Drupal\book\BookUninstallValidator|\PHPUnit\Framework\MockObject\MockObject
    */
@@ -42,7 +39,7 @@ public function testValidateNotBook() {
     $module = 'not_book';
     $expected = [];
     $reasons = $this->bookUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -59,7 +56,7 @@ public function testValidateEntityQueryWithoutResults() {
     $module = 'book';
     $expected = [];
     $reasons = $this->bookUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -76,7 +73,7 @@ public function testValidateEntityQueryWithResults() {
     $module = 'book';
     $expected = ['To uninstall Book, delete all content that has the Book content type'];
     $reasons = $this->bookUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -92,7 +89,7 @@ public function testValidateOutlineStorage() {
     $module = 'book';
     $expected = ['To uninstall Book, delete all content that is part of a book'];
     $reasons = $this->bookUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
 }
diff --git a/core/modules/breakpoint/tests/src/Kernel/BreakpointDiscoveryTest.php b/core/modules/breakpoint/tests/src/Kernel/BreakpointDiscoveryTest.php
index 495c877a978437dcd369a26e0219c93e16742b82..e8f9672e8110717ccd3d1e409cc6b3f8cc3acd5f 100644
--- a/core/modules/breakpoint/tests/src/Kernel/BreakpointDiscoveryTest.php
+++ b/core/modules/breakpoint/tests/src/Kernel/BreakpointDiscoveryTest.php
@@ -192,7 +192,7 @@ public function testBreakpointGroups() {
     ];
     $breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups();
     // Ensure the order is as expected. Should be sorted by label.
-    $this->assertIdentical($expected, $this->castSafeStrings($breakpoint_groups));
+    $this->assertEquals($expected, $breakpoint_groups);
 
     $expected = [
       'breakpoint_theme_test' => 'theme',
diff --git a/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php b/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php
index ac551ec121780c79a16e883a76da7093ac82c570..9344ab97f0d3ed65a0b0e045bdc15a6c0c76ac51 100644
--- a/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php
+++ b/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php
@@ -112,7 +112,7 @@ public function testExistingFormat() {
       ],
       'plugins' => ['language' => ['language_list' => 'un']],
     ];
-    $this->assertIdentical($this->castSafeStrings($ckeditor->getDefaultSettings()), $expected_default_settings);
+    $this->assertEquals($expected_default_settings, $ckeditor->getDefaultSettings());
 
     // Keep the "CKEditor" editor selected and click the "Configure" button.
     $this->drupalPostForm(NULL, $edit, 'editor_configure');
@@ -300,7 +300,7 @@ public function testNewFormat() {
     $expected_settings['plugins']['stylescombo']['styles'] = '';
     $editor = Editor::load('amazing_format');
     $this->assertInstanceOf(Editor::class, $editor);
-    $this->assertEqual($this->castSafeStrings($expected_settings), $this->castSafeStrings($editor->getSettings()), 'The Editor config entity has the correct settings.');
+    $this->assertEquals($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
   }
 
 }
diff --git a/core/modules/ckeditor/tests/src/Functional/CKEditorLoadingTest.php b/core/modules/ckeditor/tests/src/Functional/CKEditorLoadingTest.php
index 39c7e9a3a7766d055fdf467161f4f4cca859006e..89baa22bcb5b3638d4ff6c15870457dacc423c1c 100644
--- a/core/modules/ckeditor/tests/src/Functional/CKEditorLoadingTest.php
+++ b/core/modules/ckeditor/tests/src/Functional/CKEditorLoadingTest.php
@@ -119,14 +119,14 @@ public function testLoading() {
         'filtered_html' => [
           'format' => 'filtered_html',
           'editor' => 'ckeditor',
-          'editorSettings' => $this->castSafeStrings($ckeditor_plugin->getJSSettings($editor)),
+          'editorSettings' => $ckeditor_plugin->getJSSettings($editor),
           'editorSupportsContentFiltering' => TRUE,
           'isXssSafe' => FALSE,
         ],
       ],
     ];
     $this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
-    $this->assertIdentical($expected, $this->castSafeStrings($settings['editor']), "Text Editor module's JavaScript settings on the page are correct.");
+    $this->assertEquals($expected, $settings['editor'], "Text Editor module's JavaScript settings on the page are correct.");
     $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
     $this->assertCount(1, $body, 'A body field exists.');
     $this->assertCount(1, $format_selector, 'A single text format selector exists on the page.');
@@ -152,14 +152,14 @@ public function testLoading() {
         'filtered_html' => [
           'format' => 'filtered_html',
           'editor' => 'ckeditor',
-          'editorSettings' => $this->castSafeStrings($ckeditor_plugin->getJSSettings($editor)),
+          'editorSettings' => $ckeditor_plugin->getJSSettings($editor),
           'editorSupportsContentFiltering' => TRUE,
           'isXssSafe' => FALSE,
         ],
       ],
     ];
     $this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
-    $this->assertIdentical($expected, $this->castSafeStrings($settings['editor']), "Text Editor module's JavaScript settings on the page are correct.");
+    $this->assertEquals($expected, $settings['editor'], "Text Editor module's JavaScript settings on the page are correct.");
     $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
     $this->assertContains('ckeditor/drupal.ckeditor', explode(',', $settings['ajaxPageState']['libraries']), 'CKEditor glue library is present.');
 
diff --git a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
index 68d2b64d34907a35097fe7f585d4b63d503c8136..32e755b5ce1bc185f5920c3d57eeeca2e7487c00 100644
--- a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
+++ b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
@@ -97,10 +97,7 @@ public function testGetJSSettings() {
         'drupallink' => file_url_transform_relative(file_create_url('core/modules/ckeditor/js/plugins/drupallink/plugin.js')),
       ],
     ];
-    $expected_config = $this->castSafeStrings($expected_config);
-    ksort($expected_config);
-    ksort($expected_config['allowedContent']);
-    $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for default configuration.');
+    $this->assertEquals($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for default configuration.');
 
     // Customize the configuration: add button, have two contextually enabled
     // buttons, and configure a CKEditor plugin setting.
@@ -120,8 +117,7 @@ public function testGetJSSettings() {
     $expected_config['drupalExternalPlugins']['llama_contextual'] = file_url_transform_relative(file_create_url('core/modules/ckeditor/tests/modules/js/llama_contextual.js'));
     $expected_config['drupalExternalPlugins']['llama_contextual_and_button'] = file_url_transform_relative(file_create_url('core/modules/ckeditor/tests/modules/js/llama_contextual_and_button.js'));
     $expected_config['contentsCss'][] = file_url_transform_relative(file_create_url('core/modules/ckeditor/tests/modules/ckeditor_test.css')) . $query_string;
-    ksort($expected_config);
-    $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
+    $this->assertEquals($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
 
     // Change the allowed HTML tags; the "allowedContent" and "format_tags"
     // settings for CKEditor should automatically be updated as well.
@@ -134,8 +130,7 @@ public function testGetJSSettings() {
     $expected_config['allowedContent']['blockquote'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => TRUE];
     $expected_config['allowedContent']['address'] = ['attributes' => 'class', 'styles' => FALSE, 'classes' => 'foo,bar-*'];
     $expected_config['format_tags'] = 'p;h1;h2;h3;h4;h5;h6;pre';
-    ksort($expected_config['allowedContent']);
-    $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
+    $this->assertEquals($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
 
     // Disable the filter_html filter: allow *all *tags.
     $format->setFilterConfig('filter_html', ['status' => 0]);
@@ -144,7 +139,7 @@ public function testGetJSSettings() {
     $expected_config['allowedContent'] = TRUE;
     $expected_config['disallowedContent'] = FALSE;
     $expected_config['format_tags'] = 'p;h1;h2;h3;h4;h5;h6;pre';
-    $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
+    $this->assertEquals($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
 
     // Enable the filter_test_restrict_tags_and_attributes filter.
     $format->setFilterConfig('filter_test_restrict_tags_and_attributes', [
@@ -215,10 +210,7 @@ public function testGetJSSettings() {
       ],
     ];
     $expected_config['format_tags'] = 'p';
-    ksort($expected_config);
-    ksort($expected_config['allowedContent']);
-    ksort($expected_config['disallowedContent']);
-    $this->assertIdentical($expected_config, $this->castSafeStrings($this->ckeditor->getJSSettings($editor)), 'Generated JS settings are correct for customized configuration.');
+    $this->assertEquals($expected_config, $this->ckeditor->getJSSettings($editor), 'Generated JS settings are correct for customized configuration.');
   }
 
   /**
@@ -229,7 +221,7 @@ public function testBuildToolbarJSSetting() {
 
     // Default toolbar.
     $expected = $this->getDefaultToolbarConfig();
-    $this->assertIdentical($expected, $this->castSafeStrings($this->ckeditor->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for default toolbar.');
+    $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for default toolbar.');
 
     // Customize the configuration.
     $settings = $editor->getSettings();
@@ -237,7 +229,7 @@ public function testBuildToolbarJSSetting() {
     $editor->setSettings($settings);
     $editor->save();
     $expected[0]['items'][] = 'Strike';
-    $this->assertIdentical($expected, $this->castSafeStrings($this->ckeditor->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
+    $this->assertEquals($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
 
     // Enable the editor_test module, customize further.
     $this->enableModules(['ckeditor_test']);
@@ -249,7 +241,7 @@ public function testBuildToolbarJSSetting() {
     $editor->save();
     $expected[0]['name'] = 'JunkScience';
     $expected[0]['items'][] = 'Llama';
-    $this->assertIdentical($expected, $this->castSafeStrings($this->ckeditor->buildToolbarJSSetting($editor)), '"toolbar" configuration part of JS settings built correctly for customized toolbar with contrib module-provided CKEditor plugin.');
+    $this->assertEquals($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar with contrib module-provided CKEditor plugin.');
   }
 
   /**
@@ -261,7 +253,7 @@ public function testBuildContentsCssJSSetting() {
 
     // Default toolbar.
     $expected = $this->getDefaultContentsCssConfig();
-    $this->assertIdentical($expected, $this->ckeditor->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly for default toolbar.');
+    $this->assertEquals($expected, $this->ckeditor->buildContentsCssJSSetting($editor), '"contentsCss" configuration part of JS settings built correctly for default toolbar.');
 
     // Enable the editor_test module, which implements hook_ckeditor_css_alter().
     $this->enableModules(['ckeditor_test']);
diff --git a/core/modules/field/tests/src/Unit/FieldUninstallValidatorTest.php b/core/modules/field/tests/src/Unit/FieldUninstallValidatorTest.php
index fbc09ab0bdc6e06720953ba2695edfbc02de4f54..1a08dcf1882bf033b1eaefe41d8621b27f8ea595 100644
--- a/core/modules/field/tests/src/Unit/FieldUninstallValidatorTest.php
+++ b/core/modules/field/tests/src/Unit/FieldUninstallValidatorTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\field\Unit;
 
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -11,8 +10,6 @@
  */
 class FieldUninstallValidatorTest extends UnitTestCase {
 
-  use AssertHelperTrait;
-
   /**
    * @var \Drupal\field\FieldUninstallValidator|\PHPUnit\Framework\MockObject\MockObject
    */
@@ -48,7 +45,7 @@ public function testValidateNoStorages() {
     $module = $this->randomMachineName();
     $expected = [];
     $reasons = $this->fieldUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -68,7 +65,7 @@ public function testValidateDeleted() {
     $module = $this->randomMachineName();
     $expected = ['Fields pending deletion'];
     $reasons = $this->fieldUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -100,7 +97,7 @@ public function testValidateNoDeleted() {
     $module = $this->randomMachineName();
     $expected = ["The <em class=\"placeholder\">$field_type_label</em> field type is used in the following field: $field_name"];
     $reasons = $this->fieldUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
 }
diff --git a/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php b/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php
index e7d02aebf3533c2ca36bc32b9ce73a633f003556..8387f14e022e74df94028df5b4697fe17a5fbf21 100644
--- a/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php
+++ b/core/modules/filter/tests/src/Unit/FilterUninstallValidatorTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\filter\Unit;
 
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -11,8 +10,6 @@
  */
 class FilterUninstallValidatorTest extends UnitTestCase {
 
-  use AssertHelperTrait;
-
   /**
    * @var \Drupal\filter\FilterUninstallValidator|\PHPUnit\Framework\MockObject\MockObject
    */
@@ -43,7 +40,7 @@ public function testValidateNoPlugins() {
     $module = $this->randomMachineName();
     $expected = [];
     $reasons = $this->filterUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -65,7 +62,7 @@ public function testValidateNoFormats() {
     $module = $this->randomMachineName();
     $expected = [];
     $reasons = $this->filterUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -160,7 +157,7 @@ public function testValidateNoMatchingFormats() {
       'Provides a filter plugin that is in use in the following filter formats: <em class="placeholder">Filter Format 1 Label, Filter Format 2 Label</em>',
     ];
     $reasons = $this->filterUninstallValidator->validate($this->randomMachineName());
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
 }
diff --git a/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php b/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php
index 33067032396af0981de20dd1077fa971d2320f35..714cd9265328259f84483bfa3eabddfe1ba83b8d 100644
--- a/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php
+++ b/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests\forum\Unit;
 
 use Drupal\Core\Url;
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -12,8 +11,6 @@
  */
 class ForumUninstallValidatorTest extends UnitTestCase {
 
-  use AssertHelperTrait;
-
   /**
    * @var \Drupal\forum\ForumUninstallValidator|\PHPUnit\Framework\MockObject\MockObject
    */
@@ -45,7 +42,7 @@ public function testValidateNotForum() {
     $module = 'not_forum';
     $expected = [];
     $reasons = $this->forumUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -68,7 +65,7 @@ public function testValidate() {
     $module = 'forum';
     $expected = [];
     $reasons = $this->forumUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -93,7 +90,7 @@ public function testValidateHasForumNodes() {
       'To uninstall Forum, first delete all <em>Forum</em> content',
     ];
     $reasons = $this->forumUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -131,7 +128,7 @@ public function testValidateHasTermsForVocabularyWithNodesAccess() {
       'To uninstall Forum, first delete all <a href="/path/to/vocabulary/overview"><em class="placeholder">Vocabulary label</em></a> terms',
     ];
     $reasons = $this->forumUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -165,7 +162,7 @@ public function testValidateHasTermsForVocabularyWithNodesNoAccess() {
       'To uninstall Forum, first delete all <em class="placeholder">Vocabulary label</em> terms',
     ];
     $reasons = $this->forumUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -202,7 +199,7 @@ public function testValidateHasTermsForVocabularyAccess() {
       'To uninstall Forum, first delete all <a href="/path/to/vocabulary/overview"><em class="placeholder">Vocabulary label</em></a> terms',
     ];
     $reasons = $this->forumUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -235,7 +232,7 @@ public function testValidateHasTermsForVocabularyNoAccess() {
       'To uninstall Forum, first delete all <em class="placeholder">Vocabulary label</em> terms',
     ];
     $reasons = $this->forumUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
 }
diff --git a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
index f2e919a7e79368ea42d45d320e80a33711351a3a..cc1d570ddb8e5d82099980f6980faa014160a845 100644
--- a/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
+++ b/core/modules/rest/tests/src/Functional/Views/StyleSerializerTest.php
@@ -478,7 +478,7 @@ public function testUIFieldAlias() {
       $expected[] = $expected_row;
     }
 
-    $this->assertIdentical(Json::decode($this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']])), $this->castSafeStrings($expected));
+    $this->assertEquals($expected, Json::decode($this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']])));
 
     // Test a random aliases for fields, they should be replaced.
     $alias_map = [
@@ -513,7 +513,7 @@ public function testUIFieldAlias() {
       $expected[] = $expected_row;
     }
 
-    $this->assertIdentical(Json::decode($this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']])), $this->castSafeStrings($expected));
+    $this->assertEquals($expected, Json::decode($this->drupalGet('test/serialize/field', ['query' => ['_format' => 'json']])));
   }
 
   /**
diff --git a/core/modules/views/tests/src/Kernel/ModuleTest.php b/core/modules/views/tests/src/Kernel/ModuleTest.php
index 6c2f70787526d504225fe38c298344a7b730044c..e3b132cdcdff4f4fbcc8a4ee20b98dba1c3784af 100644
--- a/core/modules/views/tests/src/Kernel/ModuleTest.php
+++ b/core/modules/views/tests/src/Kernel/ModuleTest.php
@@ -152,14 +152,14 @@ public function testLoadFunctions() {
     foreach ($all_views as $id => $view) {
       $expected_options[$id] = $view->label();
     }
-    $this->assertIdentical($expected_options, $this->castSafeStrings(Views::getViewsAsOptions(TRUE)), 'Expected options array was returned.');
+    $this->assertIdentical($expected_options, Views::getViewsAsOptions(TRUE), 'Expected options array was returned.');
 
     // Test the default.
-    $this->assertIdentical($this->formatViewOptions($all_views), $this->castSafeStrings(Views::getViewsAsOptions()), 'Expected options array for all views was returned.');
+    $this->assertEquals($this->formatViewOptions($all_views), Views::getViewsAsOptions(), 'Expected options array for all views was returned.');
     // Test enabled views.
-    $this->assertIdentical($this->formatViewOptions($expected_enabled), $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'enabled')), 'Expected enabled options array was returned.');
+    $this->assertEquals($this->formatViewOptions($expected_enabled), Views::getViewsAsOptions(FALSE, 'enabled'), 'Expected enabled options array was returned.');
     // Test disabled views.
-    $this->assertIdentical($this->formatViewOptions($expected_disabled), $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'disabled')), 'Expected disabled options array was returned.');
+    $this->assertEquals($this->formatViewOptions($expected_disabled), Views::getViewsAsOptions(FALSE, 'disabled'), 'Expected disabled options array was returned.');
 
     // Test the sort parameter.
     $all_views_sorted = $all_views;
@@ -178,7 +178,7 @@ public function testLoadFunctions() {
         $expected_opt_groups[$view->id()][$view->id() . ':' . $display['id']] = (string) t('@view : @display', ['@view' => $view->id(), '@display' => $display['id']]);
       }
     }
-    $this->assertIdentical($expected_opt_groups, $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'all', NULL, TRUE)), 'Expected option array for an option group returned.');
+    $this->assertEquals($expected_opt_groups, Views::getViewsAsOptions(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php
index 0357a6b41117b23479dee52747e8babca92f145a..e1fd22e2659f8cd4391af73349d1f9fadf36b015 100644
--- a/core/tests/Drupal/KernelTests/AssertContentTrait.php
+++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php
@@ -802,8 +802,6 @@ protected function assertTitle($title, $message = '', $group = 'Other') {
     preg_match('@<title>(.*)</title>@', $this->getRawContent(), $matches);
     if (isset($matches[1])) {
       $actual = $matches[1];
-      $actual = $this->castSafeStrings($actual);
-      $title = $this->castSafeStrings($title);
       if (!$message) {
         $message = new FormattableMarkup('Page title @actual is equal to @expected.', [
           '@actual' => var_export($actual, TRUE),
diff --git a/core/tests/Drupal/KernelTests/Core/Plugin/InspectionTest.php b/core/tests/Drupal/KernelTests/Core/Plugin/InspectionTest.php
index a737d9a5ef88ee61b7b19c2923f47427fe3b6ca8..3541cf802c83eb307f3716c6a1460577f88bdf99 100644
--- a/core/tests/Drupal/KernelTests/Core/Plugin/InspectionTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Plugin/InspectionTest.php
@@ -31,8 +31,8 @@ public function testInspection() {
       $plugin = $this->mockBlockManager->createInstance($id);
       $expected_definition = $this->mockBlockExpectedDefinitions[$id];
       $this->assertIdentical($plugin->getPluginId(), $id);
-      $this->assertIdentical($this->castSafeStrings($this->mockBlockManager->getDefinition($id)), $expected_definition);
-      $this->assertIdentical($this->castSafeStrings($plugin->getPluginDefinition()), $expected_definition);
+      $this->assertEquals($expected_definition, $this->mockBlockManager->getDefinition($id));
+      $this->assertEquals($expected_definition, $plugin->getPluginDefinition());
     }
     // Test a plugin manager that provides defaults.
     foreach (['test_block1', 'test_block2'] as $id) {
@@ -40,7 +40,7 @@ public function testInspection() {
       $expected_definition = $this->defaultsTestPluginExpectedDefinitions[$id];
       $this->assertIdentical($plugin->getPluginId(), $id);
       $this->assertIdentical($this->defaultsTestPluginManager->getDefinition($id), $expected_definition);
-      $this->assertIdentical($this->castSafeStrings($plugin->getPluginDefinition()), $expected_definition);
+      $this->assertEquals($expected_definition, $plugin->getPluginDefinition());
     }
   }
 
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index afe40b747a9d26f26a57ed030871d73fed645135..ae72732df2da0fd73c94c4968ca9fff1ba83eb37 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -16,7 +16,6 @@
 use Drupal\Core\Language\Language;
 use Drupal\Core\Site\Settings;
 use Drupal\Core\Test\TestDatabase;
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\ConfigTestTrait;
 use Drupal\Tests\RandomGeneratorTrait;
 use Drupal\Tests\TestRequirementsTrait;
@@ -76,7 +75,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
 
   use AssertLegacyTrait;
   use AssertContentTrait;
-  use AssertHelperTrait;
   use RandomGeneratorTrait;
   use ConfigTestTrait;
   use TestRequirementsTrait;
diff --git a/core/tests/Drupal/Tests/AssertHelperTrait.php b/core/tests/Drupal/Tests/AssertHelperTrait.php
index ba814d9641d7875e6acd8ad97b43eae140bae026..29c0b29047027b6bd46af64128efc5c0c9975815 100644
--- a/core/tests/Drupal/Tests/AssertHelperTrait.php
+++ b/core/tests/Drupal/Tests/AssertHelperTrait.php
@@ -17,8 +17,14 @@ trait AssertHelperTrait {
    *
    * @return mixed
    *   The input value, with MarkupInterface objects casted to string.
+   *
+   * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There is no
+   *   replacement, just use assertEquals in tests.
+   *
+   * @see https://www.drupal.org/node/3123638
    */
   protected static function castSafeStrings($value) {
+    @trigger_error('AssertHelperTrait::castSafeStrings() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There is no replacement; assertEquals() will automatically cast MarkupInterface to strings when needed. See https://www.drupal.org/node/3123638', E_USER_DEPRECATED);
     if ($value instanceof MarkupInterface) {
       $value = (string) $value;
     }
diff --git a/core/tests/Drupal/Tests/AssertHelperTraitTest.php b/core/tests/Drupal/Tests/AssertHelperTraitTest.php
index f2e7eca6c7c3beee6e9e268d954f57fdc99bd0d4..27dbee19ef78080db47b1b9589f52be9fc473377 100644
--- a/core/tests/Drupal/Tests/AssertHelperTraitTest.php
+++ b/core/tests/Drupal/Tests/AssertHelperTraitTest.php
@@ -8,12 +8,14 @@
  * @coversDefaultClass \Drupal\Tests\AssertHelperTrait
  * @group simpletest
  * @group Tests
+ * @group legacy
  */
 class AssertHelperTraitTest extends UnitTestCase {
 
   /**
    * @covers ::castSafeStrings
    * @dataProvider providerCastSafeStrings
+   * @expectDeprecation AssertHelperTrait::castSafeStrings() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There is no replacement; assertEquals() will automatically cast MarkupInterface to strings when needed. See https://www.drupal.org/node/3123638
    */
   public function testCastSafeStrings($expected, $value) {
     $class = new AssertHelperTestClass();
diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php
index 3c2eb03d528640dad39467d2cf395812d337eeb5..a2571764ba0b41f2603e460d921e66983f0aaf1e 100644
--- a/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php
@@ -5,7 +5,6 @@
 use Drupal\Core\Extension\ModuleExtensionList;
 use Drupal\Core\Extension\ModuleRequiredByThemesUninstallValidator;
 use Drupal\Core\Extension\ThemeExtensionList;
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -14,8 +13,6 @@
  */
 class ModuleRequiredByThemesUninstallValidatorTest extends UnitTestCase {
 
-  use AssertHelperTrait;
-
   /**
    * Instance of ModuleRequiredByThemesUninstallValidator.
    *
@@ -104,7 +101,7 @@ public function testValidateOneThemeDependency() {
     ];
 
     $reasons = $this->moduleRequiredByThemeUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
   /**
@@ -151,7 +148,7 @@ public function testValidateTwoThemeDependencies() {
     ];
 
     $reasons = $this->moduleRequiredByThemeUninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
 }
diff --git a/core/tests/Drupal/Tests/Core/Extension/RequiredModuleUninstallValidatorTest.php b/core/tests/Drupal/Tests/Core/Extension/RequiredModuleUninstallValidatorTest.php
index 0bee0ee6d3da6752c17568eeb45ac5427b7c8948..4baaa19f54c26bd9bb92cc595c5ec14856a04835 100644
--- a/core/tests/Drupal/Tests/Core/Extension/RequiredModuleUninstallValidatorTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/RequiredModuleUninstallValidatorTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\Core\Extension;
 
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -11,8 +10,6 @@
  */
 class RequiredModuleUninstallValidatorTest extends UnitTestCase {
 
-  use AssertHelperTrait;
-
   /**
    * @var \Drupal\Core\Extension\RequiredModuleUninstallValidator|\PHPUnit\Framework\MockObject\MockObject
    */
@@ -71,7 +68,7 @@ public function testValidateRequired() {
 
     $expected = ["The $module module is required"];
     $reasons = $this->uninstallValidator->validate($module);
-    $this->assertSame($expected, $this->castSafeStrings($reasons));
+    $this->assertEquals($expected, $reasons);
   }
 
 }
diff --git a/core/tests/Drupal/Tests/UiHelperTrait.php b/core/tests/Drupal/Tests/UiHelperTrait.php
index 9db833596e68f424a421cd1c7d6882562db304fd..bc2b956f2d72a1cecdc7174d49d926fc9fbecaae 100644
--- a/core/tests/Drupal/Tests/UiHelperTrait.php
+++ b/core/tests/Drupal/Tests/UiHelperTrait.php
@@ -17,7 +17,6 @@
 trait UiHelperTrait {
 
   use BrowserHtmlDebugTrait;
-  use AssertHelperTrait;
   use RefreshVariablesTrait;
 
   /**
@@ -198,9 +197,6 @@ protected function drupalPostForm($path, $edit, $submit, array $options = [], $f
     if ($edit === NULL) {
       $edit = [];
     }
-    if (is_array($edit)) {
-      $edit = $this->castSafeStrings($edit);
-    }
 
     if (isset($path)) {
       $this->drupalGet($path, $options);