diff --git a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
index 97d7662..859ba09 100644
--- a/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php
@@ -59,7 +59,7 @@ protected function setUp() {
    * Tests an import with an incomplete rewinding.
    */
   public function testImportWithFailingRewind() {
-    $exception_message = $this->getRandomGenerator()->string();
+    $exception_message = $this->randomString();
     $source = $this->getMock('Drupal\migrate\Plugin\MigrateSourceInterface');
     $source->expects($this->once())
       ->method('rewind')
@@ -231,7 +231,7 @@ public function testImportWithValidRowNoDestinationValues() {
    * destination.
    */
   public function testImportWithValidRowWithDestinationMigrateException() {
-    $exception_message = $this->getRandomGenerator()->string();
+    $exception_message = $this->randomString();
     $source = $this->getMockSource();
 
     $row = $this->getMockBuilder('Drupal\migrate\Row')
@@ -282,7 +282,7 @@ public function testImportWithValidRowWithDestinationMigrateException() {
    * plugin.
    */
   public function testImportWithValidRowWithProcesMigrateException() {
-    $exception_message = $this->getRandomGenerator()->string();
+    $exception_message = $this->randomString();
     $source = $this->getMockSource();
 
     $row = $this->getMockBuilder('Drupal\migrate\Row')
@@ -328,7 +328,7 @@ public function testImportWithValidRowWithProcesMigrateException() {
    * Tests the import method with a regular Exception being thrown.
    */
   public function testImportWithValidRowWithException() {
-    $exception_message = $this->getRandomGenerator()->string();
+    $exception_message = $this->randomString();
     $source = $this->getMockSource();
 
     $row = $this->getMockBuilder('Drupal\migrate\Row')
@@ -500,4 +500,19 @@ protected function getMockSource() {
     return $source;
   }
 
+  /**
+   * @todo Use Drupal\simpletest\RandomGeneratorTrait instead?
+   */
+  protected function randomString() {
+    $length = 8;
+    // To prevent the introduction of random test failures, ensure that the
+    // returned string contains a character that needs to be escaped in HTML by
+    // injecting an ampersand into it.
+    $replacement_pos = floor($length / 2);
+    // Remove 2 from the length to account for the ampersand and greater than
+    // characters.
+    $string = $this->getRandomGenerator()->string($length - 2);
+    return substr_replace($string, '>&', $replacement_pos, 0);
+  }
+
 }
