diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
index 1ceadd1..6cfb156 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
@@ -31,15 +31,15 @@ protected function setUp() {
     $this->installConfig(['block_content']);
     $this->installEntitySchema('block_content');
 
+    // Install the themes used for this test.
+    $this->container->get('theme_installer')->install(['bartik', 'seven', 'test_theme']);
+
     // Set Bartik and Seven as the default public and admin theme.
     $config = $this->config('system.theme');
     $config->set('default', 'bartik');
     $config->set('admin', 'seven');
     $config->save();
 
-    // Install one of D8's test themes.
-    \Drupal::service('theme_handler')->install(['test_theme']);
-
     $this->executeMigrations([
       'd6_filter_format',
       'block_content_type',
@@ -87,6 +87,8 @@ public function assertEntity($id, $visibility, $region, $theme, $weight, $label,
    */
   public function testBlockMigration() {
     $blocks = Block::loadMultiple();
+    // Ensure that block_rebuild() has run.
+    block_rebuild();
     $this->assertIdentical(9, count($blocks));
 
     // User blocks
