diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
index cb35dfc497..a636e36583 100644
--- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
@@ -97,8 +97,7 @@ public function testInfoParserMissingKeys() {
       ],
     ]);
     $filename = vfsStream::url('modules/fixtures/missing_keys.info.txt');
-    $this->expectException('\Drupal\Core\Extension\InfoParserException');
-    $this->expectExceptionMessage('Missing required keys (type, name) in vfs://modules/fixtures/missing_keys.info.txt');
+    $this->setExpectedException(InfoParserException::class, 'Missing required keys (type, name) in vfs://modules/fixtures/missing_keys.info.txt');
     $this->infoParser->parse($filename);
   }
 
@@ -127,8 +126,7 @@ public function testMissingCoreCoreVersionRequirement() {
     ]);
     $exception_message = "The 'core' or the 'core_version_requirement' key must be present in vfs://modules/fixtures/missing_core_and_core_version_requirement";
     // Set the expected exception for the 2nd call to parse().
-    $this->expectException('\Drupal\Core\Extension\InfoParserException');
-    $this->expectExceptionMessage("$exception_message-duplicate.info.txt");
+    $this->setExpectedException(InfoParserException::class, "$exception_message-duplicate.info.txt");
 
     try {
       $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_and_core_version_requirement.info.txt'));
@@ -197,8 +195,7 @@ public function testCoreCoreVersionRequirement88() {
     ]);
     $exception_message = "The 'core_version_requirement' constraint (^8.8) requires the 'core' key not be set in vfs://modules/fixtures/core_and_core_version_requirement_88";
     // Set the expected exception for the 2nd call to parse().
-    $this->expectException('\Drupal\Core\Extension\InfoParserException');
-    $this->expectExceptionMessage("$exception_message-duplicate.info.txt");
+    $this->setExpectedException(InfoParserException::class, "$exception_message-duplicate.info.txt");
     try {
       $this->infoParser->parse(vfsStream::url('modules/fixtures/core_and_core_version_requirement_88.info.txt'));
     }
@@ -237,8 +234,7 @@ public function testInvalidCore() {
     ]);
     $exception_message = "Invalid 'core' value \"^8\" in vfs://modules/fixtures/invalid_core";
     // Set the expected exception for the 2nd call to parse().
-    $this->expectException('\Drupal\Core\Extension\InfoParserException');
-    $this->expectExceptionMessage("$exception_message-duplicate.info.txt");
+    $this->setExpectedException(InfoParserException::class, "$exception_message-duplicate.info.txt");
 
     try {
       $this->infoParser->parse(vfsStream::url('modules/fixtures/invalid_core.info.txt'));
@@ -279,8 +275,7 @@ public function testCoreVersionRequirementInvalid($test_case, $constraint) {
     ]);
     $exception_message = "The 'core_version_requirement' can not be used to specify compatibility for a specific version before 8.7.7 in vfs://modules/fixtures/invalid_core_version_requirement-$test_case";
     // Set the expected exception for the 2nd call to parse().
-    $this->expectException('\Drupal\Core\Extension\InfoParserException');
-    $this->expectExceptionMessage("$exception_message-duplicate.info.txt");
+    $this->setExpectedException(InfoParserException::class, "$exception_message-duplicate.info.txt");
     try {
       $this->infoParser->parse(vfsStream::url("modules/fixtures/invalid_core_version_requirement-$test_case.info.txt"));
     }
@@ -333,8 +328,7 @@ public function testInfoParserMissingKey() {
     catch (InfoParserException $exception) {
       $this->assertSame('Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt', $exception->getMessage());
 
-      $this->expectException('\Drupal\Core\Extension\InfoParserException');
-      $this->expectExceptionMessage('Missing required keys (type) in vfs://modules/fixtures/missing_key-duplicate.info.txt');
+      $this->setExpectedException(InfoParserException::class, 'Missing required keys (type) in vfs://modules/fixtures/missing_key-duplicate.info.txt');
       $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_key-duplicate.info.txt'));
     }
 
@@ -449,8 +443,7 @@ public function testInvalidProfile() {
         'invalid_profile.info.txt' => $profile,
       ],
     ]);
-    $this->expectException('\Drupal\Core\Extension\InfoParserException');
-    $this->expectExceptionMessage("The 'core_version_requirement' key is not supported in profiles in vfs://profiles/fixtures/invalid_profile.info.txt");
+    $this->setExpectedException(InfoParserException::class, "The 'core_version_requirement' key is not supported in profiles in vfs://profiles/fixtures/invalid_profile.info.txt");
     $this->infoParser->parse(vfsStream::url('profiles/fixtures/invalid_profile.info.txt'));
   }
 
@@ -476,8 +469,7 @@ public function testUnparsableCoreVersionRequirement() {
         'unparsable_core_version_requirement.info.txt' => $unparsable_core_version_requirement,
       ],
     ]);
-    $this->expectException(\UnexpectedValueException::class);
-    $this->expectExceptionMessage('Could not parse version constraint not-this-version: Invalid version string "not-this-version"');
+    $this->setExpectedException(\UnexpectedValueException::class, 'Could not parse version constraint not-this-version: Invalid version string "not-this-version"');
     $this->infoParser->parse(vfsStream::url('modules/fixtures/unparsable_core_version_requirement.info.txt'));
   }
 
