diff --git a/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php b/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php
index 01fc464cd893923810997e9e3925e346cc9db733..9206153d5b8fa05439b71302dad3b367c57c5d60 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/FileMigrationSetupTrait.php
@@ -2,36 +2,80 @@
 
 namespace Drupal\Tests\file\Kernel\Migrate\d7;
 
-use Drupal\Core\StreamWrapper\PublicStream;
-use Drupal\Core\StreamWrapper\StreamWrapperInterface;
+use Drupal\file\Entity\File;
+use Drupal\file\FileInterface;
 
 /**
  * A trait to setup the file migration.
  */
 trait FileMigrationSetupTrait {
 
+  /**
+   * Returns information about the file to be migrated.
+   *
+   * @return array
+   *   Array with keys 'path', 'size', 'base_path', and 'plugin_id'.
+   */
+  abstract protected function getFileMigrationInfo();
+
   /**
    * Prepare the file migration for running.
    */
   protected function fileMigrationSetup() {
-    $this->installSchema('file', ['file_usage']);
     $this->installEntitySchema('file');
-    $this->container->get('stream_wrapper_manager')->registerWrapper('public', PublicStream::class, StreamWrapperInterface::NORMAL);
+    $this->installSchema('file', ['file_usage']);
 
-    $fs = \Drupal::service('file_system');
-    // The public file directory active during the test will serve as the
-    // root of the fictional Drupal 7 site we're migrating.
-    $fs->mkdir('public://sites/default/files', NULL, TRUE);
-    file_put_contents('public://sites/default/files/cube.jpeg', str_repeat('*', 3620));
+    $info = $this->getFileMigrationInfo();
+    $fs = $this->container->get('file_system');
+    // Ensure that the files directory exists.
+    $fs->mkdir(dirname($info['path']), NULL, TRUE);
+    // Put test file in the source directory.
+    file_put_contents($info['path'], str_repeat('*', $info['size']));
 
     /** @var \Drupal\migrate\Plugin\Migration $migration */
-    $migration = $this->getMigration('d7_file');
+    $migration = $this->getMigration($info['plugin_id']);
     // Set the source plugin's source_base_path configuration value, which
     // would normally be set by the user running the migration.
     $source = $migration->getSourceConfiguration();
-    $source['constants']['source_base_path'] = $fs->realpath('public://');
+    $source['constants']['source_base_path'] = $fs->realpath($info['base_path']);
     $migration->set('source', $source);
     $this->executeMigration($migration);
   }
 
+  /**
+   * Tests a single file entity.
+   *
+   * @param int $id
+   *   The file ID.
+   * @param string $name
+   *   The expected file name.
+   * @param string $uri
+   *   The expected URI.
+   * @param string $mime
+   *   The expected MIME type.
+   * @param string $size
+   *   The expected file size.
+   * @param string $created
+   *   The expected creation time.
+   * @param string $changed
+   *   The expected modification time.
+   * @param string $uid
+   *   The expected owner ID.
+   */
+  protected function assertEntity($id, $name, $uri, $mime, $size, $created, $changed, $uid) {
+    /** @var \Drupal\file\FileInterface $file */
+    $file = File::load($id);
+    $this->assertInstanceOf(FileInterface::class, $file);
+    $this->assertSame($name, $file->getFilename());
+    $this->assertSame($uri, $file->getFileUri());
+    $this->assertFileExists($uri);
+    $this->assertSame($mime, $file->getMimeType());
+    $this->assertSame($size, $file->getSize());
+    // isPermanent(), isTemporary(), etc. are determined by the status column.
+    $this->assertTrue($file->isPermanent());
+    $this->assertSame($created, $file->getCreatedTime());
+    $this->assertSame($changed, $file->getChangedTime());
+    $this->assertSame($uid, $file->getOwnerId());
+  }
+
 }
diff --git a/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php
index 88d7c79e554288505d38e3ceb35469c452fbb56a..38ef4ff32008c02fe5c4bed4fa43647deb17d251 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/MigrateFileTest.php
@@ -2,8 +2,6 @@
 
 namespace Drupal\Tests\file\Kernel\Migrate\d7;
 
-use Drupal\file\Entity\File;
-use Drupal\file\FileInterface;
 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
 
 /**
@@ -15,6 +13,9 @@ class MigrateFileTest extends MigrateDrupal7TestBase {
 
   use FileMigrationSetupTrait;
 
+  /**
+   * {@inheritdoc}
+   */
   public static $modules = ['file'];
 
   /**
@@ -22,44 +23,19 @@ class MigrateFileTest extends MigrateDrupal7TestBase {
    */
   protected function setUp() {
     parent::setUp();
-
     $this->fileMigrationSetup();
   }
 
   /**
-   * Tests a single file entity.
-   *
-   * @param int $id
-   *   The file ID.
-   * @param string $name
-   *   The expected file name.
-   * @param string $uri
-   *   The expected URI.
-   * @param string $mime
-   *   The expected MIME type.
-   * @param int $size
-   *   The expected file size.
-   * @param int $created
-   *   The expected creation time.
-   * @param int $changed
-   *   The expected modification time.
-   * @param int $uid
-   *   The expected owner ID.
+   * {@inheritdoc}
    */
-  protected function assertEntity($id, $name, $uri, $mime, $size, $created, $changed, $uid) {
-    /** @var \Drupal\file\FileInterface $file */
-    $file = File::load($id);
-    $this->assertTrue($file instanceof FileInterface);
-    $this->assertIdentical($name, $file->getFilename());
-    $this->assertIdentical($uri, $file->getFileUri());
-    $this->assertTrue(file_exists($uri));
-    $this->assertIdentical($mime, $file->getMimeType());
-    $this->assertIdentical($size, $file->getSize());
-    // isPermanent(), isTemporary(), etc. are determined by the status column.
-    $this->assertTrue($file->isPermanent());
-    $this->assertIdentical($created, $file->getCreatedTime());
-    $this->assertIdentical($changed, $file->getChangedTime());
-    $this->assertIdentical($uid, $file->getOwnerId());
+  protected function getFileMigrationInfo() {
+    return [
+      'path' => 'public://sites/default/files/cube.jpeg',
+      'size' => '3620',
+      'base_path' => 'public://',
+      'plugin_id' => 'd7_file',
+    ];
   }
 
   /**
diff --git a/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php b/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php
index 7b6f763208b2bedfd0471a3c2111784b122c1d7f..63e284ff9849236c3efec9c5d94bc63c7b603d6e 100644
--- a/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php
+++ b/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php
@@ -3,8 +3,6 @@
 namespace Drupal\Tests\file\Kernel\Migrate\d7;
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\file\Entity\File;
-use Drupal\file\FileInterface;
 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
 
 /**
@@ -14,6 +12,8 @@
  */
 class MigratePrivateFileTest extends MigrateDrupal7TestBase {
 
+  use FileMigrationSetupTrait;
+
   /**
    * {@inheritdoc}
    */
@@ -25,22 +25,19 @@ class MigratePrivateFileTest extends MigrateDrupal7TestBase {
   protected function setUp() {
     parent::setUp();
     $this->setSetting('file_private_path', $this->container->get('site.path') . '/private');
-    $this->installEntitySchema('file');
-    $fs = $this->container->get('file_system');
-
-    // Ensure that the private files directory exists.
-    $fs->mkdir('private://sites/default/private/', NULL, TRUE);
-    // Put test file in the source directory.
-    file_put_contents('private://sites/default/private/Babylon5.txt', str_repeat('*', 3));
+    $this->fileMigrationSetup();
+  }
 
-    /** @var \Drupal\migrate\Plugin\Migration $migration */
-    $migration = $this->getMigration('d7_file_private');
-    // Set the source plugin's source_file_private_path configuration value,
-    // which would normally be set by the user running the migration.
-    $source = $migration->getSourceConfiguration();
-    $source['constants']['source_base_path'] = $fs->realpath('private://');
-    $migration->set('source', $source);
-    $this->executeMigration($migration);
+  /**
+   * {@inheritdoc}
+   */
+  protected function getFileMigrationInfo() {
+    return [
+      'path' => 'private://sites/default/private/Babylon5.txt',
+      'size' => '3',
+      'base_path' => 'private://',
+      'plugin_id' => 'd7_file_private',
+    ];
   }
 
   /**
@@ -52,42 +49,6 @@ public function register(ContainerBuilder $container) {
       ->addTag('stream_wrapper', ['scheme' => 'private']);
   }
 
-  /**
-   * Tests a single file entity.
-   *
-   * @param int $id
-   *   The file ID.
-   * @param string $name
-   *   The expected file name.
-   * @param string $uri
-   *   The expected URI.
-   * @param string $mime
-   *   The expected MIME type.
-   * @param int $size
-   *   The expected file size.
-   * @param int $created
-   *   The expected creation time.
-   * @param int $changed
-   *   The expected modification time.
-   * @param int $uid
-   *   The expected owner ID.
-   */
-  protected function assertEntity($id, $name, $uri, $mime, $size, $created, $changed, $uid) {
-    /** @var \Drupal\file\FileInterface $file */
-    $file = File::load($id);
-    $this->assertInstanceOf(FileInterface::class, $file);
-    $this->assertSame($name, $file->getFilename());
-    $this->assertSame($uri, $file->getFileUri());
-    $this->assertFileExists($uri);
-    $this->assertSame($mime, $file->getMimeType());
-    $this->assertSame($size, $file->getSize());
-    // isPermanent(), isTemporary(), etc. are determined by the status column.
-    $this->assertTrue($file->isPermanent());
-    $this->assertSame($created, $file->getCreatedTime());
-    $this->assertSame($changed, $file->getChangedTime());
-    $this->assertSame($uid, $file->getOwnerId());
-  }
-
   /**
    * Tests that all expected files are migrated.
    */
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php
index 96841937c8dee7dce0dfc43c3446c318098f9e5f..b9b38c2f734cf828a404febcac002fc740b3cb20 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php
@@ -61,6 +61,18 @@ protected function setUp() {
     ]);
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function getFileMigrationInfo() {
+    return [
+      'path' => 'public://sites/default/files/cube.jpeg',
+      'size' => '3620',
+      'base_path' => 'public://',
+      'plugin_id' => 'd7_file',
+    ];
+  }
+
   /**
    * Test entity reference translations.
    */
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
index bb62e90e247ad0b95c6066b9af066200b4368150..5b8a9ec97c917e6aca9f59593f48523a5b168c1b 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
@@ -71,6 +71,18 @@ protected function setUp() {
     ]);
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function getFileMigrationInfo() {
+    return [
+      'path' => 'public://sites/default/files/cube.jpeg',
+      'size' => '3620',
+      'base_path' => 'public://',
+      'plugin_id' => 'd7_file',
+    ];
+  }
+
   /**
    * Asserts various aspects of a node.
    *