diff --git a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php
index b45c916..a4cbacd 100644
--- a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php
+++ b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php
@@ -28,13 +28,12 @@ class BigPipeResponseAttachmentsProcessorTest extends UnitTestCase {
    * @covers ::processAttachments
    *
    * @dataProvider nonHtmlResponseProvider
-   *
-   * @expectedException \AssertionError
    */
   public function testNonHtmlResponse($response_class) {
     $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class));
 
     $non_html_response = new $response_class();
+    $this->setExpectedException(\AssertionError::class);
     $big_pipe_response_attachments_processor->processAttachments($non_html_response);
   }
 
diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php
index ce24cf4..898ea22 100644
--- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php
+++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\contact\Unit;
 
 use Drupal\contact\MailHandler;
+use Drupal\contact\MailHandlerException;
 use Drupal\contact\MessageInterface;
 use Drupal\Core\Language\Language;
 use Drupal\Core\Session\AccountInterface;
@@ -94,9 +95,6 @@ protected function setUp() {
   /**
    * Tests the children() method with an invalid key.
    *
-   * @expectedException \Drupal\contact\MailHandlerException
-   * @expectedExceptionMessage Unable to determine message recipient
-   *
    * @covers ::sendMailMessages
    */
   public function testInvalidRecipient() {
@@ -121,6 +119,7 @@ public function testInvalidRecipient() {
     $sender->expects($this->once())
       ->method('isAnonymous')
       ->willReturn(FALSE);
+    $this->setExpectedException(MailHandlerException::class, 'Unable to determine message recipient');
     $this->contactMailHandler->sendMailMessages($message, $sender);
   }
 
diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php
index 3a0c8aa..d1824cf 100644
--- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php
+++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php
@@ -160,9 +160,6 @@ public function testCalculateDependencies() {
 
   /**
    * Test that invalid bundles are handled.
-   *
-   * @expectedException \LogicException
-   * @expectedExceptionMessage Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.
    */
   public function testCalculateDependenciesIncorrectBundle() {
     $storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
@@ -209,6 +206,7 @@ public function testCalculateDependenciesIncorrectBundle() {
       'bundle' => 'test_bundle_not_exists',
       'field_type' => 'test_field',
     ], $this->entityTypeId);
+    $this->setExpectedException(\LogicException::class, 'Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists.');
     $field->calculateDependencies();
   }
 
diff --git a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php
index 6d876e6..4af4a3c 100644
--- a/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php
+++ b/core/modules/hal/tests/src/Unit/FieldItemNormalizerDenormalizeExceptionsUnitTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\hal\Unit;
 
 use Drupal\hal\Normalizer\FieldItemNormalizer;
+use Symfony\Component\Serializer\Exception\InvalidArgumentException;
 
 /**
  * @coversDefaultClass \Drupal\hal\Normalizer\FieldItemNormalizer
@@ -17,12 +18,12 @@ class FieldItemNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenorma
    *   Context for FieldItemNormalizer::denormalize().
    *
    * @dataProvider providerNormalizerDenormalizeExceptions
-   * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
    */
   public function testFieldItemNormalizerDenormalizeExceptions($context) {
     $field_item_normalizer = new FieldItemNormalizer();
     $data = [];
     $class = [];
+    $this->setExpectedException(InvalidArgumentException::class);
     $field_item_normalizer->denormalize($data, $class, NULL, $context);
   }
 
diff --git a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php
index 7cc55bb..792e633 100644
--- a/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php
+++ b/core/modules/hal/tests/src/Unit/FieldNormalizerDenormalizeExceptionsUnitTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\hal\Unit;
 
 use Drupal\hal\Normalizer\FieldNormalizer;
+use Symfony\Component\Serializer\Exception\InvalidArgumentException;
 
 /**
  * @coversDefaultClass \Drupal\hal\Normalizer\FieldNormalizer
@@ -17,12 +18,12 @@ class FieldNormalizerDenormalizeExceptionsUnitTest extends NormalizerDenormalize
    *   Context for FieldNormalizer::denormalize().
    *
    * @dataProvider providerNormalizerDenormalizeExceptions
-   * @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
    */
   public function testFieldNormalizerDenormalizeExceptions($context) {
     $field_item_normalizer = new FieldNormalizer();
     $data = [];
     $class = [];
+    $this->setExpectedException(InvalidArgumentException::class);
     $field_item_normalizer->denormalize($data, $class, NULL, $context);
   }
 
diff --git a/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php b/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php
index c6e62fb..695c91f 100644
--- a/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php
+++ b/core/modules/language/tests/src/Unit/process/LanguageNegotiationTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\language\Plugin\migrate\process\LanguageNegotiation;
 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
+use Drupal\migrate\MigrateException;
 
 /**
  * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageNegotiation
@@ -75,12 +76,10 @@ public function testTransformWithoutWeights() {
 
   /**
    * Tests string input.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage The input should be an array
    */
   public function testStringInput() {
     $this->plugin = new LanguageNegotiation([], 'map', []);
+    $this->setExpectedException(MigrateException::class, 'The input should be an array');
     $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
diff --git a/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php b/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php
index 17cf412..606572e 100644
--- a/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php
+++ b/core/modules/language/tests/src/Unit/process/LanguageTypesTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\language\Plugin\migrate\process\LanguageTypes;
 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
+use Drupal\migrate\MigrateException;
 
 /**
  * @coversDefaultClass \Drupal\language\Plugin\migrate\process\LanguageTypes
@@ -49,12 +50,10 @@ public function testTransformConfigurable() {
 
   /**
    * Tests string input.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage The input should be an array
    */
   public function testStringInput() {
     $this->plugin = new LanguageTypes([], 'map', []);
+    $this->setExpectedException(MigrateException::class, 'The input should be an array');
     $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
diff --git a/core/modules/locale/tests/src/Unit/StringBaseTest.php b/core/modules/locale/tests/src/Unit/StringBaseTest.php
index 58ea0ff..96bb41b 100644
--- a/core/modules/locale/tests/src/Unit/StringBaseTest.php
+++ b/core/modules/locale/tests/src/Unit/StringBaseTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\locale\Unit;
 
 use Drupal\locale\SourceString;
+use Drupal\locale\StringStorageException;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -13,22 +14,20 @@ class StringBaseTest extends UnitTestCase {
 
   /**
    * @covers ::save
-   * @expectedException \Drupal\locale\StringStorageException
-   * @expectedExceptionMessage The string cannot be saved because its not bound to a storage: test
    */
   public function testSaveWithoutStorage() {
     $string = new SourceString(['source' => 'test']);
+    $this->setExpectedException(StringStorageException::class, 'The string cannot be saved because its not bound to a storage: test');
     $string->save();
   }
 
 
   /**
    * @covers ::delete
-   * @expectedException \Drupal\locale\StringStorageException
-   * @expectedExceptionMessage The string cannot be deleted because its not bound to a storage: test
    */
   public function testDeleteWithoutStorage() {
     $string = new SourceString(['lid' => 1, 'source' => 'test']);
+    $this->setExpectedException(StringStorageException::class, 'The string cannot be deleted because its not bound to a storage: test');
     $string->delete();
   }
 
diff --git a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
index 571ec36..644371e 100644
--- a/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
+++ b/core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
@@ -139,13 +139,10 @@ public function testSuccessfulMoves() {
 
   /**
    * Test that non-existent files throw an exception.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   *
-   * @expectedExceptionMessage File '/non/existent/file' does not exist
    */
   public function testNonExistentSourceFile() {
     $source = '/non/existent/file';
+    $this->setExpectedException(MigrateException::class, "File '/non/existent/file' does not exist");
     $this->doTransform($source, 'public://wontmatter.jpg');
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
index 1258442..7f3d293 100644
--- a/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrateSourceTest.php
@@ -12,6 +12,7 @@
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
 use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
+use Drupal\migrate\MigrateException;
 use Drupal\migrate\MigrateExecutable;
 use Drupal\migrate\MigrateSkipRowException;
 use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
@@ -149,10 +150,10 @@ protected function getSource($configuration = [], $migrate_config = [], $status
 
   /**
    * @covers ::__construct
-   * @expectedException \Drupal\migrate\MigrateException
    */
   public function testHighwaterTrackChangesIncompatible() {
     $source_config = ['track_changes' => TRUE, 'high_water_property' => ['name' => 'something']];
+    $this->setExpectedException(MigrateException::class);
     $this->getSource($source_config);
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php
index 57ff64c..649104b 100644
--- a/core/modules/migrate/tests/src/Unit/MigrationTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php
@@ -27,9 +27,6 @@ class MigrationTest extends UnitTestCase {
    * Tests checking requirements for source plugins.
    *
    * @covers ::checkRequirements
-   *
-   * @expectedException \Drupal\migrate\Exception\RequirementsException
-   * @expectedExceptionMessage Missing source requirement
    */
   public function testRequirementsForSourcePlugin() {
     $migration = new TestMigration();
@@ -43,6 +40,7 @@ public function testRequirementsForSourcePlugin() {
     $migration->setSourcePlugin($source_plugin);
     $migration->setDestinationPlugin($destination_plugin);
 
+    $this->setExpectedException(RequirementsException::class, 'Missing source requirement');
     $migration->checkRequirements();
   }
 
@@ -50,9 +48,6 @@ public function testRequirementsForSourcePlugin() {
    * Tests checking requirements for destination plugins.
    *
    * @covers ::checkRequirements
-   *
-   * @expectedException \Drupal\migrate\Exception\RequirementsException
-   * @expectedExceptionMessage Missing destination requirement
    */
   public function testRequirementsForDestinationPlugin() {
     $migration = new TestMigration();
@@ -66,6 +61,7 @@ public function testRequirementsForDestinationPlugin() {
     $migration->setSourcePlugin($source_plugin);
     $migration->setDestinationPlugin($destination_plugin);
 
+    $this->setExpectedException(RequirementsException::class, 'Missing destination requirement');
     $migration->checkRequirements();
   }
 
@@ -73,9 +69,6 @@ public function testRequirementsForDestinationPlugin() {
    * Tests checking requirements for destination plugins.
    *
    * @covers ::checkRequirements
-   *
-   * @expectedException \Drupal\migrate\Exception\RequirementsException
-   * @expectedExceptionMessage Missing migrations test_a, test_c
    */
   public function testRequirementsForMigrations() {
     $migration = new TestMigration();
@@ -112,6 +105,7 @@ public function testRequirementsForMigrations() {
       ->with(['test_a', 'test_b', 'test_c', 'test_d'])
       ->willReturn(['test_b' => $migration_b, 'test_c' => $migration_c, 'test_d' => $migration_d]);
 
+    $this->setExpectedException(RequirementsException::class, 'Missing migrations test_a, test_c');
     $migration->checkRequirements();
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php
index e5d63c4..e6bb37b 100644
--- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php
+++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php
@@ -13,6 +13,7 @@
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Field\FieldTypePluginManagerInterface;
+use Drupal\migrate\MigrateException;
 use Drupal\migrate\Plugin\MigrationInterface;
 use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
 use Drupal\migrate\Plugin\MigrateIdMapInterface;
@@ -84,8 +85,6 @@ public function testImport() {
    * Test row skipping when we can't get an entity to save.
    *
    * @covers ::import
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage Unable to get entity
    */
   public function testImportEntityLoadFailure() {
     $bundles = [];
@@ -96,14 +95,12 @@ public function testImportEntityLoadFailure() {
       $this->entityManager->reveal(),
       $this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
     $destination->setEntity(FALSE);
+    $this->setExpectedException(MigrateException::class, 'Unable to get entity');
     $destination->import(new Row());
   }
 
   /**
    * Test that translation destination fails for untranslatable entities.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage This entity type does not support translation
    */
   public function testUntranslatable() {
     // An entity type without a language.
@@ -125,6 +122,7 @@ public function testUntranslatable() {
       $this->entityManager->reveal(),
       $this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
     );
+    $this->setExpectedException(MigrateException::class, 'This entity type does not support translation');
     $destination->getIds();
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php
index aa3a7d9..10d7d7d 100644
--- a/core/modules/migrate/tests/src/Unit/RowTest.php
+++ b/core/modules/migrate/tests/src/Unit/RowTest.php
@@ -73,20 +73,17 @@ public function testRowWithMultipleSourceIds() {
 
   /**
    * Tests object creation: invalid values.
-   *
-   * @expectedException \Exception
    */
   public function testRowWithInvalidData() {
     $invalid_values = [
       'title' => 'node X',
     ];
+    $this->setExpectedException(\Exception::class);
     $row = new Row($invalid_values, $this->testSourceIds);
   }
 
   /**
    * Tests source immutability after freeze.
-   *
-   * @expectedException \Exception
    */
   public function testSourceFreeze() {
     $row = new Row($this->testValues, $this->testSourceIds);
@@ -96,18 +93,17 @@ public function testSourceFreeze() {
     $row->rehash();
     $this->assertSame($this->testHashMod, $row->getHash(), 'Hash changed correctly.');
     $row->freezeSource();
+    $this->setExpectedException(\Exception::class);
     $row->setSourceProperty('title', 'new title');
   }
 
   /**
    * Tests setting on a frozen row.
-   *
-   * @expectedException \Exception
-   * @expectedExceptionMessage The source is frozen and can't be changed any more
    */
   public function testSetFrozenRow() {
     $row = new Row($this->testValues, $this->testSourceIds);
     $row->freezeSource();
+    $this->setExpectedException(\Exception::class, "The source is frozen and can't be changed any more");
     $row->setSourceProperty('title', 'new title');
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php
index cae7cc0..ea93e46 100644
--- a/core/modules/migrate/tests/src/Unit/process/ConcatTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/ConcatTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Tests\migrate\Unit\process;
 
+use Drupal\migrate\MigrateException;
 use Drupal\migrate\Plugin\migrate\process\Concat;
 
 /**
@@ -34,10 +35,9 @@ public function testConcatWithoutDelimiter() {
 
   /**
    * Test concat fails properly on non-arrays.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
    */
   public function testConcatWithNonArray() {
+    $this->setExpectedException(MigrateException::class);
     $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php
index 3245e60..0cd0db2 100644
--- a/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/ExplodeTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\migrate\Unit\process;
 
+use Drupal\migrate\MigrateException;
 use Drupal\migrate\Plugin\migrate\process\Explode;
 use Drupal\migrate\Plugin\migrate\process\Concat;
 
@@ -53,24 +54,18 @@ public function testChainedTransform() {
 
   /**
    * Test explode fails properly on non-strings.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   *
-   * @expectedExceptionMessage is not a string
    */
   public function testExplodeWithNonString() {
+    $this->setExpectedException(MigrateException::class, 'is not a string');
     $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
   /**
    * Test explode fails with empty delimiter.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   *
-   * @expectedExceptionMessage delimiter is empty
    */
   public function testExplodeWithEmptyDelimiter() {
     $plugin = new Explode(['delimiter' => ''], 'map', []);
+    $this->setExpectedException(MigrateException::class, 'delimiter is empty');
     $plugin->transform('foo,bar', $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php
index d030a07..14f3f9a 100644
--- a/core/modules/migrate/tests/src/Unit/process/ExtractTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/ExtractTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\migrate\Unit\process;
 
+use Drupal\migrate\MigrateException;
 use Drupal\migrate\Plugin\migrate\process\Extract;
 
 /**
@@ -29,21 +30,17 @@ public function testExtract() {
 
   /**
    * Tests invalid input.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage Input should be an array.
    */
   public function testExtractFromString() {
+    $this->setExpectedException(MigrateException::class, 'Input should be an array.');
     $this->plugin->transform('bar', $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
   /**
    * Tests unsuccessful extraction.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage Array index missing, extraction failed.
    */
   public function testExtractFail() {
+    $this->setExpectedException(MigrateException::class, 'Array index missing, extraction failed.');
     $this->plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php
index b62c1f9..dfac1c9 100644
--- a/core/modules/migrate/tests/src/Unit/process/MigrationTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\migrate\Unit\process;
 
 use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\migrate\MigrateSkipProcessException;
 use Drupal\migrate\Plugin\MigrationInterface;
 use Drupal\migrate\Plugin\migrate\process\Migration;
 use Drupal\migrate\Plugin\MigrateDestinationInterface;
@@ -89,8 +90,6 @@ public function testTransformWithStubbing() {
 
   /**
    * Tests that processing is skipped when the input value is empty.
-   *
-   * @expectedException \Drupal\migrate\MigrateSkipProcessException
    */
   public function testSkipOnEmpty() {
     $migration_plugin = $this->prophesize(MigrationInterface::class);
@@ -102,6 +101,7 @@ public function testSkipOnEmpty() {
     ];
     $migration_plugin->id()->willReturn(uniqid());
     $migration = new Migration($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
+    $this->setExpectedException(MigrateSkipProcessException::class);
     $migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php
index bf40dac..66b27cc 100644
--- a/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/SkipOnEmptyTest.php
@@ -1,6 +1,8 @@
 <?php
 
 namespace Drupal\Tests\migrate\Unit\process;
+use Drupal\migrate\MigrateSkipProcessException;
+use Drupal\migrate\MigrateSkipRowException;
 use Drupal\migrate\Plugin\migrate\process\SkipOnEmpty;
 
 /**
@@ -13,10 +15,10 @@ class SkipOnEmptyTest extends MigrateProcessTestCase {
 
   /**
    * @covers ::process
-   * @expectedException \Drupal\migrate\MigrateSkipProcessException
    */
   public function testProcessSkipsOnEmpty() {
     $configuration['method'] = 'process';
+    $this->setExpectedException(MigrateSkipProcessException::class);
     (new SkipOnEmpty($configuration, 'skip_on_empty', []))
       ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
   }
@@ -33,10 +35,10 @@ public function testProcessBypassesOnNonEmpty() {
 
   /**
    * @covers ::row
-   * @expectedException \Drupal\migrate\MigrateSkipRowException
    */
   public function testRowSkipsOnEmpty() {
     $configuration['method'] = 'row';
+    $this->setExpectedException(MigrateSkipRowException::class);
     (new SkipOnEmpty($configuration, 'skip_on_empty', []))
       ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
   }
diff --git a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php
index 5a8de13..714d5f7 100644
--- a/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/StaticMapTest.php
@@ -2,6 +2,8 @@
 
 namespace Drupal\Tests\migrate\Unit\process;
 
+use Drupal\migrate\MigrateException;
+use Drupal\migrate\MigrateSkipRowException;
 use Drupal\migrate\Plugin\migrate\process\StaticMap;
 
 /**
@@ -38,19 +40,17 @@ public function testMapWithSourceList() {
 
   /**
    * Tests when the source is empty.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
    */
   public function testMapwithEmptySource() {
+    $this->setExpectedException(MigrateException::class);
     $this->plugin->transform([], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
   /**
    * Tests when the source is invalid.
-   *
-   * @expectedException \Drupal\migrate\MigrateSkipRowException
    */
   public function testMapwithInvalidSource() {
+    $this->setExpectedException(MigrateSkipRowException::class);
     $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
@@ -78,15 +78,13 @@ public function testMapWithInvalidSourceWithANullDefaultValue() {
 
   /**
    * Tests when the source is invalid and bypass is enabled.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage Setting both default_value and bypass is invalid.
    */
   public function testMapWithInvalidSourceAndBypass() {
     $configuration['map']['foo']['bar'] = 'baz';
     $configuration['default_value'] = 'test';
     $configuration['bypass'] = TRUE;
     $this->plugin = new StaticMap($configuration, 'map', []);
+    $this->setExpectedException(MigrateException::class, 'Setting both default_value and bypass is invalid.');
     $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
diff --git a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php
index fb84509..6a73905 100644
--- a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\migrate\Unit\process;
 
+use Drupal\migrate\MigrateException;
 use Drupal\migrate\Plugin\migrate\process\Substr;
 
 /**
@@ -55,37 +56,31 @@ public function providerTestSubstr() {
 
   /**
    * Tests invalid input type.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage The input value must be a string.
    */
   public function testSubstrFail() {
     $configuration = [];
     $this->plugin = new Substr($configuration, 'map', []);
+    $this->setExpectedException(MigrateException::class, 'The input value must be a string.');
     $this->plugin->transform(['Captain Janeway'], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
   /**
    * Tests that the start parameter is an integer.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.
    */
   public function testStartIsString() {
     $configuration['start'] = '2';
     $this->plugin = new Substr($configuration, 'map', []);
+    $this->setExpectedException(MigrateException::class, 'The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.');
     $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
   /**
    * Tests that the length parameter is an integer.
-   *
-   * @expectedException \Drupal\migrate\MigrateException
-   * @expectedExceptionMessage The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.
    */
   public function testLengthIsString() {
     $configuration['length'] = '1';
     $this->plugin = new Substr($configuration, 'map', []);
+    $this->setExpectedException(MigrateException::class, 'The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.');
     $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
   }
 
diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
index eb894ca..f195da6 100644
--- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
+++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
@@ -6,6 +6,7 @@
 use Drupal\Core\Field\FieldItemListInterface;
 use Drupal\serialization\Normalizer\EntityNormalizer;
 use Drupal\Tests\UnitTestCase;
+use Symfony\Component\Serializer\Exception\UnexpectedValueException;
 
 /**
  * @coversDefaultClass \Drupal\serialization\Normalizer\EntityNormalizer
@@ -84,10 +85,9 @@ public function testNormalize() {
    * Tests the denormalize() method with no entity type provided in context.
    *
    * @covers ::denormalize
-   *
-   * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
    */
   public function testDenormalizeWithNoEntityType() {
+    $this->setExpectedException(UnexpectedValueException::class);
     $this->entityNormalizer->denormalize([], 'Drupal\Core\Entity\ContentEntityBase');
   }
 
@@ -215,8 +215,6 @@ public function testDenormalizeWithValidBundle() {
   /**
    * Tests the denormalize method with a bundle property.
    *
-   * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
-   *
    * @covers ::denormalize
    */
   public function testDenormalizeWithInvalidBundle() {
@@ -288,6 +286,7 @@ public function testDenormalizeWithInvalidBundle() {
       ->with('test_bundle')
       ->will($this->returnValue($entity_type_storage));
 
+    $this->setExpectedException(UnexpectedValueException::class);
     $this->assertNotNull($this->entityNormalizer->denormalize($test_data, 'Drupal\Core\Entity\ContentEntityBase', NULL, ['entity_type' => 'test']));
   }
 
diff --git a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php
index df98377..f36243e 100644
--- a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php
+++ b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php
@@ -10,6 +10,7 @@
 use Composer\Autoload\ClassLoader;
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\simpletest\Exception\MissingGroupException;
 use Drupal\simpletest\TestDiscovery;
 use Drupal\Tests\UnitTestCase;
 use org\bovigo\vfs\vfsStream;
@@ -235,8 +236,6 @@ public function infoParserProvider() {
 
   /**
    * @covers ::getTestInfo
-   * @expectedException \Drupal\simpletest\Exception\MissingGroupException
-   * @expectedExceptionMessage Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest
    */
   public function testTestInfoParserMissingGroup() {
     $classname = 'Drupal\KernelTests\field\BulkDeleteTest';
@@ -245,6 +244,7 @@ public function testTestInfoParserMissingGroup() {
  * Bulk delete storages and fields, and clean up afterwards.
  */
 EOT;
+    $this->setExpectedException(MissingGroupException::class, 'Missing @group annotation in Drupal\KernelTests\field\BulkDeleteTest');
     TestDiscovery::getTestInfo($classname, $doc_comment);
   }
 
diff --git a/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php b/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php
index 16bb08f..fc044d5 100644
--- a/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php
+++ b/core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php
@@ -6,6 +6,7 @@
 use Drupal\Tests\Core\Routing\RoutingFixtures;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
 
 /**
  * Confirm that the mime types partial matcher is functioning properly.
@@ -86,9 +87,6 @@ public function testAcceptFiltering($accept_header, $format, $included_route, $e
 
   /**
    * Confirms that the AcceptHeaderMatcher throws an exception for no-route.
-   *
-   * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException
-   * @expectedExceptionMessage No route found for the specified formats application/json text/xml.
    */
   public function testNoRouteFound() {
     // Remove the sample routes that would match any method.
@@ -103,6 +101,7 @@ public function testNoRouteFound() {
     $request->setRequestFormat('json');
     $this->matcher->filter($routes, $request);
     $this->matcher->filter($routes, $request);
+    $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified formats application/json text/xml.');
     $this->fail('No exception was thrown.');
   }
 
diff --git a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php
index 1aa2f66..cb7f5eb 100644
--- a/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php
+++ b/core/modules/system/tests/src/Kernel/Scripts/DbCommandBaseTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\system\Kernel\Scripts;
 
 use Drupal\Core\Command\DbCommandBase;
+use Drupal\Core\Database\ConnectionNotDefinedException;
 use Drupal\Core\Database\Database;
 use Drupal\KernelTests\KernelTestBase;
 use Symfony\Component\Console\Input\InputInterface;
@@ -42,8 +43,6 @@ public function testSpecifyDatabaseKey() {
 
   /**
    * Invalid database names will throw a useful exception.
-   *
-   * @expectedException \Drupal\Core\Database\ConnectionNotDefinedException
    */
   public function testSpecifyDatabaseDoesNotExist() {
     $command = new DbCommandBaseTester();
@@ -51,6 +50,7 @@ public function testSpecifyDatabaseDoesNotExist() {
     $command_tester->execute([
       '--database' => 'dne'
     ]);
+    $this->setExpectedException(ConnectionNotDefinedException::class);
     $command->getDatabaseConnection($command_tester->getInput());
   }
 
diff --git a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php
index c038b71..8d18811 100644
--- a/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php
+++ b/core/modules/user/tests/src/Unit/PrivateTempStoreTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Tests\UnitTestCase;
 use Drupal\user\PrivateTempStore;
+use Drupal\user\TempStoreException;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\RequestStack;
 
@@ -121,7 +122,6 @@ public function testGet() {
    * Tests the set() method with no lock available.
    *
    * @covers ::set
-   * @expectedException \Drupal\user\TempStoreException
    */
   public function testSetWithNoLockAvailable() {
     $this->lock->expects($this->at(0))
@@ -139,6 +139,7 @@ public function testSetWithNoLockAvailable() {
     $this->keyValue->expects($this->once())
       ->method('getCollectionName');
 
+    $this->setExpectedException(TempStoreException::class);
     $this->tempStore->set('test', 'value');
   }
 
@@ -220,7 +221,6 @@ public function testDeleteLocking() {
    * Tests the delete() method with no lock available.
    *
    * @covers ::delete
-   * @expectedException \Drupal\user\TempStoreException
    */
   public function testDeleteWithNoLockAvailable() {
     $this->keyValue->expects($this->once())
@@ -242,6 +242,7 @@ public function testDeleteWithNoLockAvailable() {
     $this->keyValue->expects($this->once())
       ->method('getCollectionName');
 
+    $this->setExpectedException(TempStoreException::class);
     $this->tempStore->delete('test');
   }
 
diff --git a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php
index ba556a3..33bde41 100644
--- a/core/modules/user/tests/src/Unit/SharedTempStoreTest.php
+++ b/core/modules/user/tests/src/Unit/SharedTempStoreTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Tests\UnitTestCase;
 use Drupal\user\SharedTempStore;
+use Drupal\user\TempStoreException;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\RequestStack;
 
@@ -132,7 +133,6 @@ public function testGetIfOwner() {
    * Tests the set() method with no lock available.
    *
    * @covers ::set
-   * @expectedException \Drupal\user\TempStoreException
    */
   public function testSetWithNoLockAvailable() {
     $this->lock->expects($this->at(0))
@@ -150,6 +150,7 @@ public function testSetWithNoLockAvailable() {
     $this->keyValue->expects($this->once())
       ->method('getCollectionName');
 
+    $this->setExpectedException(TempStoreException::class);
     $this->tempStore->set('test', 'value');
   }
 
@@ -296,7 +297,6 @@ public function testDelete() {
    * Tests the delete() method with no lock available.
    *
    * @covers ::delete
-   * @expectedException \Drupal\user\TempStoreException
    */
   public function testDeleteWithNoLockAvailable() {
     $this->lock->expects($this->at(0))
@@ -314,6 +314,7 @@ public function testDeleteWithNoLockAvailable() {
     $this->keyValue->expects($this->once())
       ->method('getCollectionName');
 
+    $this->setExpectedException(TempStoreException::class);
     $this->tempStore->delete('test');
   }
 
diff --git a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
index 5483ee4..f766975 100644
--- a/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
+++ b/core/modules/views/tests/src/Unit/Controller/ViewAjaxControllerTest.php
@@ -9,6 +9,8 @@
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 
 /**
  * @coversDefaultClass \Drupal\views\Controller\ViewAjaxController
@@ -113,18 +115,15 @@ protected function setUp() {
 
   /**
    * Tests missing view_name and view_display_id
-   *
-   * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
    */
   public function testMissingViewName() {
     $request = new Request();
+    $this->setExpectedException(NotFoundHttpException::class);
     $this->viewAjaxController->ajaxView($request);
   }
 
   /**
    * Tests with view_name and view_display_id but not existing view.
-   *
-   * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
    */
   public function testMissingView() {
     $request = new Request();
@@ -136,13 +135,12 @@ public function testMissingView() {
       ->with('test_view')
       ->will($this->returnValue(FALSE));
 
+    $this->setExpectedException(NotFoundHttpException::class);
     $this->viewAjaxController->ajaxView($request);
   }
 
   /**
    * Tests a view without having access to it.
-   *
-   * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
    */
   public function testAccessDeniedView() {
     $request = new Request();
@@ -170,6 +168,7 @@ public function testAccessDeniedView() {
       ->with($view)
       ->will($this->returnValue($executable));
 
+    $this->setExpectedException(AccessDeniedHttpException::class);
     $this->viewAjaxController->ajaxView($request);
   }
 
diff --git a/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php b/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php
index 55ead47..f009183 100644
--- a/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php
+++ b/core/modules/views/tests/src/Unit/Plugin/display/PageTest.php
@@ -30,9 +30,9 @@ public function testBuildBasicRenderable() {
 
   /**
    * @covers ::buildBasicRenderable
-   * @expectedException \BadFunctionCallException
    */
   public function testBuildBasicRenderableWithMissingRoute() {
+    $this->setExpectedException(\BadFunctionCallException::class);
     Page::buildBasicRenderable('test_view', 'page_1', []);
   }
 
diff --git a/core/modules/views/tests/src/Unit/ViewExecutableTest.php b/core/modules/views/tests/src/Unit/ViewExecutableTest.php
index 6abcd99..f30a19d 100644
--- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php
+++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php
@@ -182,8 +182,6 @@ public function testGetUrlWithPathNoPlaceholders() {
   }
 
   /**
-   * @expectedException \InvalidArgumentException
-   *
    * @covers ::getUrl
    */
   public function testGetUrlWithoutRouterDisplay() {
@@ -193,6 +191,7 @@ public function testGetUrlWithoutRouterDisplay() {
       ->willReturn($this->displayHandler);
     $this->executable->display_handler = $this->displayHandler;
 
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->executable->getUrl();
   }
 
diff --git a/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php b/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php
index 18a2c48..c9ef715 100644
--- a/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php
+++ b/core/modules/workflows/tests/src/Kernel/RequiredStatesTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\workflows\Entity\Workflow;
+use Drupal\workflows\Exception\RequiredStateMissingException;
 
 /**
  * Tests Workflow type's required states and configuration initialization.
@@ -42,8 +43,6 @@ public function testGetRequiredStates() {
 
   /**
    * @covers \Drupal\workflows\Entity\Workflow::preSave
-   * @expectedException \Drupal\workflows\Exception\RequiredStateMissingException
-   * @expectedExceptionMessage Required State Type Test' requires states with the ID 'fresh' in workflow 'test'
    */
   public function testDeleteRequiredStateAPI() {
     $workflow = new Workflow([
@@ -53,19 +52,19 @@ public function testDeleteRequiredStateAPI() {
     $workflow = $workflow->getTypePlugin()->initializeWorkflow($workflow);
     $workflow->save();
     // Ensure that required states can't be deleted.
+    $this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh' in workflow 'test'");
     $workflow->deleteState('fresh')->save();
   }
 
   /**
    * @covers \Drupal\workflows\Entity\Workflow::preSave
-   * @expectedException \Drupal\workflows\Exception\RequiredStateMissingException
-   * @expectedExceptionMessage Required State Type Test' requires states with the ID 'fresh', 'rotten' in workflow 'test'
    */
   public function testNoStatesRequiredStateAPI() {
     $workflow = new Workflow([
       'id' => 'test',
       'type' => 'workflow_type_required_state_test',
     ], 'workflow');
+    $this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh', 'rotten' in workflow 'test'");
     $workflow->save();
   }
 
diff --git a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php
index cd42ad1..8fab307 100644
--- a/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php
+++ b/core/tests/Drupal/KernelTests/Component/Utility/SafeMarkupKernelTest.php
@@ -107,10 +107,10 @@ public function providerTestSafeMarkupUri() {
 
   /**
    * @dataProvider providerTestSafeMarkupUriWithException
-   * @expectedException \InvalidArgumentException
    */
   public function testSafeMarkupUriWithExceptionUri($string, $uri) {
     // Should throw an \InvalidArgumentException, due to Uri::toString().
+    $this->setExpectedException(\InvalidArgumentException::class);
     $args = self::getSafeMarkupUriArgs($uri);
 
     SafeMarkup::format($string, $args);
diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php
index 98423ca..627b903 100644
--- a/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeRenderAndAutoescapeTest.php
@@ -82,10 +82,9 @@ public function providerTestThemeRenderAndAutoescape() {
 
   /**
    * Ensures invalid content is handled correctly.
-   *
-   * @expectedException \Exception
    */
   public function testThemeEscapeAndRenderNotPrintable() {
+    $this->setExpectedException(\Exception::class);
     theme_render_and_autoescape(new NonPrintable());
   }
 
diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
index 8aa9d9a..6cd5575 100644
--- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
+++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php
@@ -10,6 +10,11 @@
 use Drupal\Component\Utility\Crypt;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
+use Symfony\Component\DependencyInjection\Exception\LogicException;
+use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
+use Symfony\Component\DependencyInjection\Exception\RuntimeException;
+use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
+use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
 use Prophecy\Argument;
 
 /**
@@ -60,12 +65,11 @@ protected function setUp() {
    * Tests that passing a non-supported format throws an InvalidArgumentException.
    *
    * @covers ::__construct
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
    */
   public function testConstruct() {
     $container_definition = $this->getMockContainerDefinition();
     $container_definition['machine_format'] = !$this->machineFormat;
+    $this->setExpectedException(InvalidArgumentException::class);
     $container = new $this->containerClass($container_definition);
   }
 
@@ -86,10 +90,9 @@ public function testGetParameter() {
    * @covers ::getParameter
    * @covers ::getParameterAlternatives
    * @covers ::getAlternatives
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
    */
   public function testGetParameterIfNotFound() {
+    $this->setExpectedException(ParameterNotFoundException::class);
     $this->container->getParameter('parameter_that_does_not_exist');
   }
 
@@ -97,10 +100,9 @@ public function testGetParameterIfNotFound() {
    * Tests that Container::getParameter() works properly for NULL parameters.
    *
    * @covers ::getParameter
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
    */
   public function testGetParameterIfNotFoundBecauseNull() {
+    $this->setExpectedException(ParameterNotFoundException::class);
     $this->container->getParameter(NULL);
   }
 
@@ -131,11 +133,10 @@ public function testSetParameterWithUnfrozenContainer() {
    * Tests that Container::setParameter() in a frozen case works properly.
    *
    * @covers ::setParameter
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
    */
   public function testSetParameterWithFrozenContainer() {
     $this->container = new $this->containerClass($this->containerDefinition);
+    $this->setExpectedException(LogicException::class);
     $this->container->setParameter('some_config', 'new_value');
   }
 
@@ -236,11 +237,11 @@ public function testHasForAliasedService() {
 
   /**
    * Tests that Container::get() for circular dependencies works properly.
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
    * @covers ::get
    * @covers ::createService
    */
   public function testGetForCircularServices() {
+    $this->setExpectedException(ServiceCircularReferenceException::class);
     $this->container->get('circular_dependency');
   }
 
@@ -251,10 +252,9 @@ public function testGetForCircularServices() {
    * @covers ::createService
    * @covers ::getAlternatives
    * @covers ::getServiceAlternatives
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
    */
   public function testGetForNonExistantService() {
+    $this->setExpectedException(ServiceNotFoundException::class);
     $this->container->get('service_not_exists');
   }
 
@@ -296,8 +296,6 @@ public function testGetForNonExistantParameterDependency() {
    * @covers ::get
    * @covers ::createService
    * @covers ::resolveServicesAndParameters
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
    */
   public function testGetForParameterDependencyWithExceptionOnSecondCall() {
     $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE);
@@ -305,6 +303,7 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() {
 
     // Reset the service.
     $this->container->set('service_parameter_not_exists', NULL);
+    $this->setExpectedException(InvalidArgumentException::class);
     $this->container->get('service_parameter_not_exists');
   }
 
@@ -314,10 +313,9 @@ public function testGetForParameterDependencyWithExceptionOnSecondCall() {
    * @covers ::get
    * @covers ::createService
    * @covers ::resolveServicesAndParameters
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
    */
   public function testGetForNonExistantParameterDependencyWithException() {
+    $this->setExpectedException(InvalidArgumentException::class);
     $this->container->get('service_parameter_not_exists');
   }
 
@@ -340,10 +338,9 @@ public function testGetForNonExistantServiceDependency() {
    * @covers ::createService
    * @covers ::resolveServicesAndParameters
    * @covers ::getAlternatives
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
    */
   public function testGetForNonExistantServiceDependencyWithException() {
+    $this->setExpectedException(ServiceNotFoundException::class);
     $this->container->get('service_dependency_not_exists');
   }
 
@@ -361,10 +358,9 @@ public function testGetForNonExistantServiceWhenUsingNull() {
    * Tests that Container::get() for NULL service works properly.
    * @covers ::get
    * @covers ::createService
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
    */
   public function testGetForNonExistantNULLService() {
+    $this->setExpectedException(ServiceNotFoundException::class);
     $this->container->get(NULL);
   }
 
@@ -387,11 +383,10 @@ public function testGetForNonExistantServiceMultipleTimes() {
    * @covers ::get
    * @covers ::createService
    * @covers ::getAlternatives
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
    */
   public function testGetForNonExistantServiceWithExceptionOnSecondCall() {
     $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does nto throw exception.');
+    $this->setExpectedException(ServiceNotFoundException::class);
     $this->container->get('service_not_exists');
   }
 
@@ -425,10 +420,9 @@ public function testGetForSyntheticService() {
    *
    * @covers ::get
    * @covers ::createService
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
    */
   public function testGetForSyntheticServiceWithException() {
+    $this->setExpectedException(RuntimeException::class);
     $this->container->get('synthetic');
   }
 
@@ -465,10 +459,9 @@ public function testGetForInstantiationWithVariousArgumentLengths() {
    *
    * @covers ::get
    * @covers ::createService
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
    */
   public function testGetForWrongFactory() {
+    $this->setExpectedException(RuntimeException::class);
     $this->container->get('wrong_factory');
   }
 
@@ -504,10 +497,9 @@ public function testGetForFactoryClass() {
    *
    * @covers ::get
    * @covers ::createService
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
    */
   public function testGetForConfiguratorWithException() {
+    $this->setExpectedException(InvalidArgumentException::class);
     $this->container->get('configurable_service_exception');
   }
 
@@ -603,10 +595,9 @@ public function testResolveServicesAndParametersForOptionalServiceDependencies()
    * @covers ::get
    * @covers ::createService
    * @covers ::resolveServicesAndParameters
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
    */
   public function testResolveServicesAndParametersForInvalidArgument() {
+    $this->setExpectedException(InvalidArgumentException::class);
     $this->container->get('invalid_argument_service');
   }
 
@@ -616,12 +607,11 @@ public function testResolveServicesAndParametersForInvalidArgument() {
    * @covers ::get
    * @covers ::createService
    * @covers ::resolveServicesAndParameters
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
    */
   public function testResolveServicesAndParametersForInvalidArguments() {
     // In case the machine-optimized format is not used, we need to simulate the
     // test failure.
+    $this->setExpectedException(InvalidArgumentException::class);
     if (!$this->machineFormat) {
       throw new InvalidArgumentException('Simulating the test failure.');
     }
@@ -672,8 +662,6 @@ public function testInitializedForAliases() {
    * @covers ::hasScope
    * @covers ::isScopeActive
    *
-   * @expectedException \BadMethodCallException
-   *
    * @dataProvider scopeExceptionTestProvider
    */
   public function testScopeFunctionsWithException($method, $argument) {
@@ -682,6 +670,7 @@ public function testScopeFunctionsWithException($method, $argument) {
       $method,
     ];
 
+    $this->setExpectedException(\BadMethodCallException::class);
     $callable($argument);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
index a899aaa..9da4c27 100644
--- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
+++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
@@ -14,6 +14,8 @@
   use Symfony\Component\ExpressionLanguage\Expression;
   use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
   use Symfony\Component\DependencyInjection\ContainerInterface;
+  use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
+  use Symfony\Component\DependencyInjection\Exception\RuntimeException;
 
   /**
    * @coversDefaultClass \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper
@@ -482,8 +484,6 @@ protected function getServiceCall($id, $invalid_behavior = ContainerInterface::E
      * Tests that the correct InvalidArgumentException is thrown for getScope().
      *
      * @covers ::getServiceDefinition
-     *
-     * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
      */
     public function testGetServiceDefinitionWithInvalidScope() {
       $bar_definition = new Definition('\stdClass');
@@ -491,6 +491,7 @@ public function testGetServiceDefinitionWithInvalidScope() {
       $services['bar'] = $bar_definition;
 
       $this->containerBuilder->getDefinitions()->willReturn($services);
+      $this->setExpectedException(InvalidArgumentException::class);
       $this->dumper->getArray();
     }
 
@@ -555,8 +556,6 @@ public function publicPrivateDataProvider() {
      * getDecoratedService().
      *
      * @covers ::getServiceDefinition
-     *
-     * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
      */
     public function testGetServiceDefinitionForDecoratedService() {
       $bar_definition = new Definition('\stdClass');
@@ -564,6 +563,7 @@ public function testGetServiceDefinitionForDecoratedService() {
       $services['bar'] = $bar_definition;
 
       $this->containerBuilder->getDefinitions()->willReturn($services);
+      $this->setExpectedException(InvalidArgumentException::class);
       $this->dumper->getArray();
     }
 
@@ -571,8 +571,6 @@ public function testGetServiceDefinitionForDecoratedService() {
      * Tests that the correct RuntimeException is thrown for expressions.
      *
      * @covers ::dumpValue
-     *
-     * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
      */
     public function testGetServiceDefinitionForExpression() {
       $expression = new Expression();
@@ -582,6 +580,7 @@ public function testGetServiceDefinitionForExpression() {
       $services['bar'] = $bar_definition;
 
       $this->containerBuilder->getDefinitions()->willReturn($services);
+      $this->setExpectedException(RuntimeException::class);
       $this->dumper->getArray();
     }
 
@@ -589,8 +588,6 @@ public function testGetServiceDefinitionForExpression() {
      * Tests that the correct RuntimeException is thrown for dumping an object.
      *
      * @covers ::dumpValue
-     *
-     * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
      */
     public function testGetServiceDefinitionForObject() {
       $service = new \stdClass();
@@ -600,6 +597,7 @@ public function testGetServiceDefinitionForObject() {
       $services['bar'] = $bar_definition;
 
       $this->containerBuilder->getDefinitions()->willReturn($services);
+      $this->setExpectedException(RuntimeException::class);
       $this->dumper->getArray();
     }
 
@@ -607,8 +605,6 @@ public function testGetServiceDefinitionForObject() {
      * Tests that the correct RuntimeException is thrown for dumping a resource.
      *
      * @covers ::dumpValue
-     *
-     * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
      */
     public function testGetServiceDefinitionForResource() {
       $resource = fopen('php://memory', 'r');
@@ -618,6 +614,7 @@ public function testGetServiceDefinitionForResource() {
       $services['bar'] = $bar_definition;
 
       $this->containerBuilder->getDefinitions()->willReturn($services);
+      $this->setExpectedException(RuntimeException::class);
       $this->dumper->getArray();
     }
 
diff --git a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php
index a7db812..1ed036e 100644
--- a/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php
+++ b/core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php
@@ -55,12 +55,10 @@ public function testGet() {
 
   /**
    * @covers ::get
-   *
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage Required prefix configuration is missing
    */
   public function testGetNoPrefix() {
     FileCacheFactory::setPrefix(NULL);
+    $this->setExpectedException(\InvalidArgumentException::class, 'Required prefix configuration is missing');
     FileCacheFactory::get('test_foo_settings', []);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php
index 1fc805b..28a48f6 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultFactoryTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Component\Plugin;
 
 use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
+use Drupal\Component\Plugin\Exception\PluginException;
 use Drupal\Component\Plugin\Factory\DefaultFactory;
 use Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry;
 use Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface;
@@ -47,11 +48,9 @@ public function testGetPluginClassWithValidObjectPluginDefinition() {
    * Tests getPluginClass() with a missing class definition.
    *
    * @covers ::getPluginClass
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
-   * @expectedExceptionMessage The plugin (cherry) did not specify an instance class.
    */
   public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
+    $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
     DefaultFactory::getPluginClass('cherry', []);
   }
 
@@ -59,12 +58,10 @@ public function testGetPluginClassWithMissingClassWithArrayPluginDefinition() {
    * Tests getPluginClass() with a missing class definition.
    *
    * @covers ::getPluginClass
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
-   * @expectedExceptionMessage The plugin (cherry) did not specify an instance class.
    */
   public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
     $plugin_definition = $this->getMock(PluginDefinitionInterface::class);
+    $this->setExpectedException(PluginException::class, 'The plugin (cherry) did not specify an instance class.');
     DefaultFactory::getPluginClass('cherry', $plugin_definition);
   }
 
@@ -72,11 +69,9 @@ public function testGetPluginClassWithMissingClassWithObjectPluginDefinition() {
    * Tests getPluginClass() with a not existing class definition.
    *
    * @covers ::getPluginClass
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
-   * @expectedExceptionMessage Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.
    */
   public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition() {
+    $this->setExpectedException(PluginException::class, 'Plugin (kiwifruit) instance class "\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit" does not exist.');
     DefaultFactory::getPluginClass('kiwifruit', ['class' => '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit']);
   }
 
@@ -84,8 +79,6 @@ public function testGetPluginClassWithNotExistingClassWithArrayPluginDefinition(
    * Tests getPluginClass() with a not existing class definition.
    *
    * @covers ::getPluginClass
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
    */
   public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition() {
     $plugin_class = '\Drupal\plugin_test\Plugin\plugin_test\fruit\Kiwifruit';
@@ -93,6 +86,7 @@ public function testGetPluginClassWithNotExistingClassWithObjectPluginDefinition
     $plugin_definition->expects($this->atLeastOnce())
       ->method('getClass')
       ->willReturn($plugin_class);
+    $this->setExpectedException(PluginException::class);
     DefaultFactory::getPluginClass('kiwifruit', $plugin_definition);
   }
 
@@ -128,12 +122,10 @@ public function testGetPluginClassWithInterfaceWithObjectPluginDefinition() {
    * Tests getPluginClass() with a required interface but no implementation.
    *
    * @covers ::getPluginClass
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
-   * @expectedExceptionMessage Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.
    */
   public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDefinition() {
     $plugin_class = Kale::class;
+    $this->setExpectedException(PluginException::class, 'Plugin "cherry" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface.');
     DefaultFactory::getPluginClass('cherry', ['class' => $plugin_class, 'provider' => 'core'], FruitInterface::class);
   }
 
@@ -141,8 +133,6 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithArrayPluginDef
    * Tests getPluginClass() with a required interface but no implementation.
    *
    * @covers ::getPluginClass
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
    */
   public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDefinition() {
     $plugin_class = Kale::class;
@@ -150,6 +140,7 @@ public function testGetPluginClassWithInterfaceAndInvalidClassWithObjectPluginDe
     $plugin_definition->expects($this->atLeastOnce())
       ->method('getClass')
       ->willReturn($plugin_class);
+    $this->setExpectedException(PluginException::class);
     DefaultFactory::getPluginClass('cherry', $plugin_definition, FruitInterface::class);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php
index 74a8c43..04268d2 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Component\Plugin\Discovery;
 
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -58,7 +59,6 @@ public function providerDoGetDefinitionException() {
 
   /**
    * @covers ::doGetDefinition
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
    * @dataProvider providerDoGetDefinitionException
    * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException
    */
@@ -69,6 +69,7 @@ public function testDoGetDefinitionException($expected, $definitions, $plugin_id
     $method_ref = new \ReflectionMethod($trait, 'doGetDefinition');
     $method_ref->setAccessible(TRUE);
     // Call doGetDefinition, with $exception_on_invalid always TRUE.
+    $this->setExpectedException(PluginNotFoundException::class);
     $this->assertSame(
       $expected,
       $method_ref->invoke($trait, $definitions, $plugin_id, TRUE)
@@ -96,7 +97,6 @@ public function testGetDefinition($expected, $definitions, $plugin_id) {
 
   /**
    * @covers ::getDefinition
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
    * @dataProvider providerDoGetDefinitionException
    * @uses \Drupal\Component\Plugin\Exception\PluginNotFoundException
    */
@@ -109,6 +109,7 @@ public function testGetDefinitionException($expected, $definitions, $plugin_id)
       ->method('getDefinitions')
       ->willReturn($definitions);
     // Call getDefinition(), with $exception_on_invalid always TRUE.
+    $this->setExpectedException(PluginNotFoundException::class);
     $this->assertSame(
       $expected,
       $trait->getDefinition($plugin_id, TRUE)
diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
index ef0d7fb..3884031 100644
--- a/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
+++ b/core/tests/Drupal/Tests/Component/Serialization/YamlPeclTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Component\Serialization;
 
+use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
 use Drupal\Component\Serialization\YamlPecl;
 
 /**
@@ -74,9 +75,9 @@ public function testGetFileExtension() {
    * Tests that invalid YAML throws an exception.
    *
    * @covers ::errorHandler
-   * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException
    */
   public function testError() {
+    $this->setExpectedException(InvalidDataTypeException::class);
     YamlPecl::decode('foo: [ads');
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php
index 3101efe..f9c2fb9 100644
--- a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php
+++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Component\Serialization;
 
+use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
 use Drupal\Component\Serialization\YamlSymfony;
 
 /**
@@ -56,9 +57,9 @@ public function testGetFileExtension() {
    * Tests that invalid YAML throws an exception.
    *
    * @covers ::decode
-   * @expectedException \Drupal\Component\Serialization\Exception\InvalidDataTypeException
    */
   public function testError() {
+    $this->setExpectedException(InvalidDataTypeException::class);
     YamlSymfony::decode('foo: [ads');
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
index 878bbfd..4dbc8a7 100644
--- a/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.php
@@ -121,9 +121,6 @@ public function testGetArgumentOrder() {
    * Tests getArgument() with a wildcard parameter with no typehint.
    *
    * Without the typehint, the wildcard object will not be passed to the callable.
-   *
-   * @expectedException \RuntimeException
-   * @expectedExceptionMessage requires a value for the "$route" argument.
    */
   public function testGetWildcardArgumentNoTypehint() {
     $a = $this->getMock('\Drupal\Tests\Component\Utility\TestInterface1');
@@ -131,6 +128,7 @@ public function testGetWildcardArgumentNoTypehint() {
     $resolver = new ArgumentsResolver([], [], $wildcards);
 
     $callable = function($route) {};
+    $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.');
     $arguments = $resolver->getArguments($callable);
     $this->assertNull($arguments);
   }
@@ -152,9 +150,6 @@ public function testGetArgumentRouteNoTypehintAndValue() {
 
   /**
    * Tests handleUnresolvedArgument() for a scalar argument.
-   *
-   * @expectedException \RuntimeException
-   * @expectedExceptionMessage requires a value for the "$foo" argument.
    */
   public function testHandleNotUpcastedArgument() {
     $objects = ['foo' => 'bar'];
@@ -162,6 +157,7 @@ public function testHandleNotUpcastedArgument() {
     $resolver = new ArgumentsResolver($scalars, $objects, []);
 
     $callable = function(\stdClass $foo) {};
+    $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
     $arguments = $resolver->getArguments($callable);
     $this->assertNull($arguments);
   }
@@ -169,13 +165,11 @@ public function testHandleNotUpcastedArgument() {
   /**
    * Tests handleUnresolvedArgument() for missing arguments.
    *
-   * @expectedException \RuntimeException
-   * @expectedExceptionMessage requires a value for the "$foo" argument.
-   *
    * @dataProvider providerTestHandleUnresolvedArgument
    */
   public function testHandleUnresolvedArgument($callable) {
     $resolver = new ArgumentsResolver([], [], []);
+    $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.');
     $arguments = $resolver->getArguments($callable);
     $this->assertNull($arguments);
   }
diff --git a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php
index f709171..38743df 100644
--- a/core/tests/Drupal/Tests/Component/Utility/CryptTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/CryptTest.php
@@ -69,7 +69,6 @@ public function testHmacBase64($data, $key, $expected_hmac) {
    * Tests the hmacBase64 method with invalid parameters.
    *
    * @dataProvider providerTestHmacBase64Invalid
-   * @expectedException InvalidArgumentException
    * @covers ::hmacBase64
    *
    * @param string $data
@@ -78,6 +77,7 @@ public function testHmacBase64($data, $key, $expected_hmac) {
    *   Key to use in hashing process.
    */
   public function testHmacBase64Invalid($data, $key) {
+    $this->setExpectedException(\InvalidArgumentException::class);
     Crypt::hmacBase64($data, $key);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
index 8bab1c7..593ebc5 100644
--- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php
@@ -332,9 +332,9 @@ public function testTransformRootRelativeUrlsToAbsolute($html, $scheme_and_host,
   /**
    * @covers ::transformRootRelativeUrlsToAbsolute
    * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion
-   * @expectedException \AssertionError
    */
   public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) {
+    $this->setExpectedException(\AssertionError::class);
     Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php
index e8cc6f6..b122c3a 100644
--- a/core/tests/Drupal/Tests/Component/Utility/RandomTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/RandomTest.php
@@ -57,12 +57,12 @@ public function testRandomNamesUniqueness() {
    * Tests infinite loop prevention whilst generating random names.
    *
    * @covers ::name
-   * @expectedException \RuntimeException
    */
   public function testRandomNameException() {
     // There are fewer than 100 possibilities so an exception should occur to
     // prevent infinite loops.
     $random = new Random();
+    $this->setExpectedException(\RuntimeException::class);
     for ($i = 0; $i <= 100; $i++) {
       $str = $random->name(1, TRUE);
       $names[$str] = TRUE;
@@ -73,12 +73,12 @@ public function testRandomNameException() {
    * Tests infinite loop prevention whilst generating random strings.
    *
    * @covers ::string
-   * @expectedException \RuntimeException
    */
   public function testRandomStringException() {
     // There are fewer than 100 possibilities so an exception should occur to
     // prevent infinite loops.
     $random = new Random();
+    $this->setExpectedException(\RuntimeException::class);
     for ($i = 0; $i <= 100; $i++) {
       $str = $random->string(1, TRUE);
       $names[$str] = TRUE;
diff --git a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php
index 0aa29a6..1f7394a 100644
--- a/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/RectangleTest.php
@@ -15,10 +15,9 @@ class RectangleTest extends UnitTestCase {
    * Tests wrong rectangle width.
    *
    * @covers ::rotate
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testWrongWidth() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $rect = new Rectangle(-40, 20);
   }
 
@@ -26,10 +25,9 @@ public function testWrongWidth() {
    * Tests wrong rectangle height.
    *
    * @covers ::rotate
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testWrongHeight() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $rect = new Rectangle(40, 0);
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
index e487831..41d1739 100644
--- a/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
+++ b/core/tests/Drupal/Tests/Component/Utility/UrlHelperTest.php
@@ -560,9 +560,9 @@ public function providerTestExternalIsLocal() {
    *
    * @covers ::externalIsLocal
    * @dataProvider providerTestExternalIsLocalInvalid
-   * @expectedException \InvalidArgumentException
    */
   public function testExternalIsLocalInvalid($url, $base_url) {
+    $this->setExpectedException(\InvalidArgumentException::class);
     UrlHelper::externalIsLocal($url, $base_url);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php
index c2a1da7..231f809 100644
--- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Access;
 
 use Drupal\Core\Access\AccessCheckInterface;
+use Drupal\Core\Access\AccessException;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Access\CheckProvider;
 use Drupal\Core\Cache\Context\CacheContextsManager;
@@ -474,8 +475,6 @@ public function testCheckNamedRouteWithNonExistingRoute() {
    * Tests that an access checker throws an exception for not allowed values.
    *
    * @dataProvider providerCheckException
-   *
-   * @expectedException \Drupal\Core\Access\AccessException
    */
   public function testCheckException($return_value) {
     $route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
@@ -515,6 +514,7 @@ public function testCheckException($return_value) {
     $this->checkProvider->setContainer($container);
     $this->checkProvider->addCheckService('test_incorrect_value', 'access');
 
+    $this->setExpectedException(AccessException::class);
     $access_manager->checkNamedRoute('test_incorrect_value', [], $this->account);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
index cc4691d..52ed59c 100644
--- a/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Access/CsrfTokenGeneratorTest.php
@@ -171,11 +171,11 @@ public function providerTestValidateParameterTypes() {
    *
    * @covers ::validate
    * @dataProvider providerTestInvalidParameterTypes
-   * @expectedException InvalidArgumentException
    */
   public function testInvalidParameterTypes($token, $value = '') {
     $this->setupDefaultExpectations();
 
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->generator->validate($token, $value);
   }
 
@@ -198,12 +198,12 @@ public function providerTestInvalidParameterTypes() {
    * Tests the exception thrown when no 'hash_salt' is provided in settings.
    *
    * @covers ::get
-   * @expectedException \RuntimeException
    */
   public function testGetWithNoHashSalt() {
     // Update settings with no hash salt.
     new Settings([]);
     $generator = new CsrfTokenGenerator($this->privateKey, $this->sessionMetadata);
+    $this->setExpectedException(\RuntimeException::class);
     $generator->get();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php
index ca71c81..f65d932 100644
--- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php
+++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php
@@ -7,6 +7,9 @@
 
 namespace Drupal\Tests\Core\Asset;
 
+use Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException;
+use Drupal\Core\Asset\Exception\InvalidLibraryFileException;
+use Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException;
 use Drupal\Core\Asset\LibraryDiscoveryParser;
 use Drupal\Tests\UnitTestCase;
 
@@ -143,8 +146,6 @@ public function testBuildByExtensionWithMissingLibraryFile() {
   /**
    * Tests that an exception is thrown when a libraries file couldn't be parsed.
    *
-   * @expectedException \Drupal\Core\Asset\Exception\InvalidLibraryFileException
-   *
    * @covers ::buildByExtension
    */
   public function testInvalidLibrariesFile() {
@@ -157,15 +158,13 @@ public function testInvalidLibrariesFile() {
     $path = substr($path, strlen($this->root) + 1);
     $this->libraryDiscoveryParser->setPaths('module', 'invalid_file', $path);
 
+    $this->setExpectedException(InvalidLibraryFileException::class);
     $this->libraryDiscoveryParser->buildByExtension('invalid_file');
   }
 
   /**
    * Tests that an exception is thrown when no CSS/JS/setting is specified.
    *
-   * @expectedException \Drupal\Core\Asset\Exception\IncompleteLibraryDefinitionException
-   * @expectedExceptionMessage Incomplete library definition for definition 'example' in extension 'example_module_missing_information'
-   *
    * @covers ::buildByExtension
    */
   public function testBuildByExtensionWithMissingInformation() {
@@ -178,6 +177,7 @@ public function testBuildByExtensionWithMissingInformation() {
     $path = substr($path, strlen($this->root) + 1);
     $this->libraryDiscoveryParser->setPaths('module', 'example_module_missing_information', $path);
 
+    $this->setExpectedException(IncompleteLibraryDefinitionException::class, "Incomplete library definition for definition 'example' in extension 'example_module_missing_information'");
     $this->libraryDiscoveryParser->buildByExtension('example_module_missing_information');
   }
 
@@ -276,8 +276,6 @@ public function testDefaultCssWeights() {
   /**
    * Ensures that you cannot provide positive weights for JavaScript libraries.
    *
-   * @expectedException \UnexpectedValueException
-   *
    * @covers ::buildByExtension
    */
   public function testJsWithPositiveWeight() {
@@ -290,6 +288,7 @@ public function testJsWithPositiveWeight() {
     $path = substr($path, strlen($this->root) + 1);
     $this->libraryDiscoveryParser->setPaths('module', 'js_positive_weight', $path);
 
+    $this->setExpectedException(\UnexpectedValueException::class);
     $this->libraryDiscoveryParser->buildByExtension('js_positive_weight');
   }
 
@@ -403,9 +402,6 @@ public function testLibraryWithJavaScript() {
   /**
    * Tests that an exception is thrown when license is missing when 3rd party.
    *
-   * @expectedException \Drupal\Core\Asset\Exception\LibraryDefinitionMissingLicenseException
-   * @expectedExceptionMessage Missing license information in library definition for definition 'no-license-info-but-remote' extension 'licenses_missing_information': it has a remote, but no license.
-   *
    * @covers ::buildByExtension
    */
   public function testLibraryThirdPartyWithMissingLicense() {
@@ -418,6 +414,7 @@ public function testLibraryThirdPartyWithMissingLicense() {
     $path = substr($path, strlen($this->root) + 1);
     $this->libraryDiscoveryParser->setPaths('module', 'licenses_missing_information', $path);
 
+    $this->setExpectedException(LibraryDefinitionMissingLicenseException::class, "Missing license information in library definition for definition 'no-license-info-but-remote' extension 'licenses_missing_information': it has a remote, but no license.");
     $this->libraryDiscoveryParser->buildByExtension('licenses_missing_information');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php
index be1469c..aed60a6 100644
--- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbManagerTest.php
@@ -183,8 +183,6 @@ public function testBuildWithOneNotApplyingBuilders() {
 
   /**
    * Tests a breadcrumb builder with a bad return value.
-   *
-   * @expectedException \UnexpectedValueException
    */
   public function testBuildWithInvalidBreadcrumbResult() {
     $builder = $this->getMock('Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface');
@@ -196,6 +194,7 @@ public function testBuildWithInvalidBreadcrumbResult() {
       ->will($this->returnValue('invalid_result'));
 
     $this->breadcrumbManager->addBuilder($builder, 0);
+    $this->setExpectedException(\UnexpectedValueException::class);
     $this->breadcrumbManager->build($this->getMock('Drupal\Core\Routing\RouteMatchInterface'));
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php
index ca8acfc..67c7d98 100644
--- a/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php
+++ b/core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php
@@ -15,12 +15,11 @@ class BreadcrumbTest extends UnitTestCase {
 
   /**
    * @covers ::setLinks
-   * @expectedException \LogicException
-   * @expectedExceptionMessage Once breadcrumb links are set, only additional breadcrumb links can be added.
    */
   public function testSetLinks() {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->setLinks([new Link('Home', Url::fromRoute('<front>'))]);
+    $this->setExpectedException(\LogicException::class, 'Once breadcrumb links are set, only additional breadcrumb links can be added.');
     $breadcrumb->setLinks([new Link('None', Url::fromRoute('<none>'))]);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php
index 3c41bdb..5466a09 100644
--- a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php
+++ b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php
@@ -14,11 +14,10 @@ class CacheTagsInvalidatorTest extends UnitTestCase {
 
   /**
    * @covers ::invalidateTags
-   *
-   * @expectedException \AssertionError
    */
   public function testInvalidateTagsWithInvalidTags() {
     $cache_tags_invalidator = new CacheTagsInvalidator();
+    $this->setExpectedException(\AssertionError::class);
     $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php
index e68dd9b..f89e639 100644
--- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php
@@ -105,27 +105,25 @@ public function testConvertTokensToKeys() {
 
   /**
    * @covers ::convertTokensToKeys
-   *
-   * @expectedException \AssertionError
    */
   public function testInvalidContext() {
     $container = $this->getMockContainer();
     $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture());
 
+    $this->setExpectedException(\AssertionError::class);
     $cache_contexts_manager->convertTokensToKeys(["non-cache-context"]);
   }
 
   /**
    * @covers ::convertTokensToKeys
    *
-   * @expectedException \Exception
-   *
    * @dataProvider providerTestInvalidCalculatedContext
    */
   public function testInvalidCalculatedContext($context_token) {
     $container = $this->getMockContainer();
     $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture());
 
+    $this->setExpectedException(\Exception::class);
     $cache_contexts_manager->convertTokensToKeys([$context_token]);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php
index ef1db21..41c3e93 100644
--- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php
@@ -6,6 +6,7 @@
 use Drupal\Core\Render\Markup;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Config\Config;
+use Drupal\Core\Config\ConfigValueException;
 
 /**
  * Tests the Config.
@@ -230,21 +231,21 @@ public function testSetValue($data) {
 
   /**
    * @covers ::set
-   * @expectedException \Drupal\Core\Config\ConfigValueException
    */
   public function testSetValidation() {
+    $this->setExpectedException(ConfigValueException::class);
     $this->config->set('testData', ['dot.key' => 1]);
   }
 
   /**
    * @covers ::set
-   * @expectedException PHPUnit_Framework_Error_Warning
    */
   public function testSetIllegalOffsetValue() {
     // Set a single value.
     $this->config->set('testData', 1);
 
     // Attempt to treat the single value as a nested item.
+    $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class);
     $this->config->set('testData.illegalOffset', 1);
   }
 
@@ -383,7 +384,6 @@ public function mergeDataProvider() {
 
   /**
    * @covers ::validateName
-   * @expectedException \Drupal\Core\Config\ConfigNameException
    * @dataProvider validateNameProvider
    */
   public function testValidateNameException($name, $exception_message) {
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
index 171f2d3..0a5d3d3 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Config\Entity;
 
 use Drupal\Component\Plugin\PluginManagerInterface;
+use Drupal\Core\Config\Schema\SchemaIncompleteException;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Language\Language;
 use Drupal\Core\Plugin\DefaultLazyPluginCollection;
@@ -567,13 +568,12 @@ public function testToArraySchemaFallback() {
 
   /**
    * @covers ::toArray
-   *
-   * @expectedException \Drupal\Core\Config\Schema\SchemaIncompleteException
    */
   public function testToArrayFallback() {
     $this->entityType->expects($this->any())
       ->method('getPropertiesToExport')
       ->willReturn([]);
+    $this->setExpectedException(SchemaIncompleteException::class);
     $this->entity->toArray();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
index 230b085..c4540e1 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@@ -6,6 +6,7 @@
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
 use Drupal\Core\Config\Config;
+use Drupal\Core\Config\ConfigDuplicateUUIDException;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Config\ConfigManagerInterface;
 use Drupal\Core\Config\Entity\ConfigEntityBase;
@@ -15,7 +16,9 @@
 use Drupal\Core\Config\ImmutableConfig;
 use Drupal\Core\Config\TypedConfigManagerInterface;
 use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityMalformedException;
 use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityStorageException;
 use Drupal\Core\Entity\Query\QueryFactoryInterface;
 use Drupal\Core\Entity\Query\QueryInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -376,23 +379,19 @@ public function testSaveRename(ConfigEntityInterface $entity) {
 
   /**
    * @covers ::save
-   *
-   * @expectedException \Drupal\Core\Entity\EntityMalformedException
-   * @expectedExceptionMessage The entity does not have an ID.
    */
   public function testSaveInvalid() {
     $this->cacheTagsInvalidator->invalidateTags(Argument::cetera())
       ->shouldNotBeCalled();
 
     $entity = $this->getMockEntity();
+    $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.');
     $this->entityStorage->save($entity);
   }
 
   /**
    * @covers ::save
    * @covers ::doSave
-   *
-   * @expectedException \Drupal\Core\Entity\EntityStorageException
    */
   public function testSaveDuplicate() {
     $config_object = $this->prophesize(ImmutableConfig::class);
@@ -407,15 +406,13 @@ public function testSaveDuplicate() {
     $entity = $this->getMockEntity(['id' => 'foo']);
     $entity->enforceIsNew();
 
+    $this->setExpectedException(EntityStorageException::class);
     $this->entityStorage->save($entity);
   }
 
   /**
    * @covers ::save
    * @covers ::doSave
-   *
-   * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException
-   * @expectedExceptionMessage when this UUID is already used for
    */
   public function testSaveMismatch() {
     $config_object = $this->prophesize(ImmutableConfig::class);
@@ -431,6 +428,7 @@ public function testSaveMismatch() {
     $this->entityQuery->execute()->willReturn(['baz']);
 
     $entity = $this->getMockEntity(['id' => 'foo']);
+    $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this UUID is already used for');
     $this->entityStorage->save($entity);
   }
 
@@ -472,9 +470,6 @@ public function testSaveNoMismatch() {
   /**
    * @covers ::save
    * @covers ::doSave
-   *
-   * @expectedException \Drupal\Core\Config\ConfigDuplicateUUIDException
-   * @expectedExceptionMessage when this entity already exists with UUID
    */
   public function testSaveChangedUuid() {
     $config_object = $this->prophesize(ImmutableConfig::class);
@@ -504,6 +499,7 @@ public function testSaveChangedUuid() {
     $entity = $this->getMockEntity(['id' => 'foo']);
 
     $entity->set('uuid', 'baz');
+    $this->setExpectedException(ConfigDuplicateUUIDException::class, 'when this entity already exists with UUID');
     $this->entityStorage->save($entity);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php
index 928cebc..914d4f6 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Config\Entity\ConfigEntityType;
+use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException;
 
 /**
  * @coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityType
@@ -79,11 +80,9 @@ public function testConstruct() {
 
   /**
    * @covers ::__construct
-   *
-   * @expectedException \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
-   * @expectedExceptionMessage \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it
    */
   public function testConstructBadStorage() {
+    $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it');
     new ConfigEntityType([
       'id' => 'example_config_entity_type',
       'handlers' => ['storage' => '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage']
@@ -92,12 +91,10 @@ public function testConstructBadStorage() {
 
   /**
    * @covers ::setStorageClass
-   *
-   * @expectedException \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
-   * @expectedExceptionMessage \Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it
    */
   public function testSetStorageClass() {
     $config_entity = $this->setUpConfigEntityType([]);
+    $this->setExpectedException(ConfigEntityStorageClassException::class, '\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it');
     $config_entity->setStorageClass('\Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php
index 75fe625..f3c882c 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php
@@ -96,8 +96,8 @@ public function providerTestGetKeys() {
   }
 
   /**
-   * @expectedException \LogicException
-   * @expectedExceptionMessage test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup
+   * @covers ::getKeys
+   * @covers ::getValues
    */
   public function testGetKeysWildCardEnd() {
     $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
@@ -111,6 +111,7 @@ public function testGetKeysWildCardEnd() {
 
     $method = new \ReflectionMethod($query_factory, 'getKeys');
     $method->setAccessible(TRUE);
+    $this->setExpectedException(\LogicException::class, 'test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup');
     $method->invoke($query_factory, $this->getConfigObject('test'), 'test.*', 'get', $config_entity_type);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php
index 5b5c498..0ac8299 100644
--- a/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/ImmutableConfigTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Core\Config;
 
 use Drupal\Core\Config\ImmutableConfig;
+use Drupal\Core\Config\ImmutableConfigException;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -28,37 +29,33 @@ protected function setUp() {
 
   /**
    * @covers ::set
-   * @expectedException \Drupal\Core\Config\ImmutableConfigException
-   * @expectedExceptionMessage Can not set values on immutable configuration test:name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object
    */
   public function testSet() {
+    $this->setExpectedException(ImmutableConfigException::class, 'Can not set values on immutable configuration test:name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object');
     $this->config->set('name', 'value');
   }
 
   /**
    * @covers ::clear
-   * @expectedException \Drupal\Core\Config\ImmutableConfigException
-   * @expectedExceptionMessage Can not clear name key in immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object
    */
   public function testClear() {
+    $this->setExpectedException(ImmutableConfigException::class, 'Can not clear name key in immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object');
     $this->config->clear('name');
   }
 
   /**
    * @covers ::save
-   * @expectedException \Drupal\Core\Config\ImmutableConfigException
-   * @expectedExceptionMessage Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object
    */
   public function testSave() {
+    $this->setExpectedException(ImmutableConfigException::class, 'Can not save immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object');
     $this->config->save();
   }
 
   /**
    * @covers ::delete
-   * @expectedException \Drupal\Core\Config\ImmutableConfigException
-   * @expectedExceptionMessage Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object
    */
   public function testDelete() {
+    $this->setExpectedException(ImmutableConfigException::class, 'Can not delete immutable configuration test. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object');
     $this->config->delete();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php
index ef9c076..28040a6 100644
--- a/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php
+++ b/core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php
@@ -120,19 +120,17 @@ public function providerTestCreateController() {
 
   /**
    * Tests createController() with a non-existent class.
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testCreateControllerNonExistentClass() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->controllerResolver->getControllerFromDefinition('Class::method');
   }
 
   /**
    * Tests createController() with an invalid name.
-   *
-   * @expectedException \LogicException
    */
   public function testCreateControllerInvalidName() {
+    $this->setExpectedException(\LogicException::class);
     $this->controllerResolver->getControllerFromDefinition('ClassWithoutMethod');
   }
 
@@ -191,10 +189,9 @@ public function providerTestGetControllerFromDefinition() {
   }
   /**
    * Tests getControllerFromDefinition() without a callable.
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testGetControllerFromDefinitionNotCallable() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->controllerResolver->getControllerFromDefinition('Drupal\Tests\Core\Controller\MockController::bananas');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php
index f33e3c3..13b6293 100644
--- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php
+++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php
@@ -140,7 +140,6 @@ public function dataProviderTestCompileWithKnownOperators() {
   /**
    * @covers ::compile
    *
-   * @expectedException \PHPUnit_Framework_Error
    * @dataProvider providerTestCompileWithSqlInjectionForOperator
    */
   public function testCompileWithSqlInjectionForOperator($operator) {
@@ -162,6 +161,7 @@ public function testCompileWithSqlInjectionForOperator($operator) {
 
     $condition = new Condition('AND');
     $condition->condition('name', 'value', $operator);
+    $this->setExpectedException(\PHPUnit_Framework_Error::class);
     $condition->compile($connection, $query_placeholder);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php
index b43971d..aea2524 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/ProxyServicesPassTest.php
@@ -5,6 +5,7 @@
 use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Tests\UnitTestCase;
+use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
 
 /**
  * @coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass
@@ -64,14 +65,13 @@ public function testContainerWithLazyServices() {
 
   /**
    * @covers ::process
-   *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
    */
   public function testContainerWithLazyServicesWithoutProxyClass() {
     $container = new ContainerBuilder();
     $container->register('alias_whitelist', 'Drupal\Core\Path\AliasWhitelist')
       ->setLazy(TRUE);
 
+    $this->setExpectedException(InvalidArgumentException::class);
     $this->proxyServicesPass->process($container);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php
index 9335b7d..7e7381f 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/TaggedHandlersPassTest.php
@@ -10,6 +10,7 @@
 use Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Exception\LogicException;
 use Symfony\Component\DependencyInjection\Reference;
 
 /**
@@ -44,8 +45,6 @@ public function testProcessNoConsumers() {
   /**
    * Tests a required consumer with no handlers.
    *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
-   * @expectedExceptionMessage At least one service tagged with 'consumer_id' is required.
    * @covers ::process
    */
   public function testProcessRequiredHandlers() {
@@ -57,14 +56,13 @@ public function testProcessRequiredHandlers() {
       ]);
 
     $handler_pass = new TaggedHandlersPass();
+    $this->setExpectedException(LogicException::class, "At least one service tagged with 'consumer_id' is required.");
     $handler_pass->process($container);
   }
 
   /**
    * Tests consumer with missing interface in non-production environment.
    *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
-   * @expectedExceptionMessage Service consumer 'consumer_id1' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface.
    * @covers ::process
    */
   public function testProcessMissingInterface() {
@@ -77,6 +75,7 @@ public function testProcessMissingInterface() {
       ->addTag('service_collector');
 
     $handler_pass = new TaggedHandlersPass();
+    $this->setExpectedException(LogicException::class, "Service consumer 'consumer_id1' class method Drupal\Tests\Core\DependencyInjection\Compiler\InvalidConsumer::addHandler() has to type-hint an interface.");
     $handler_pass->process($container);
   }
 
@@ -207,7 +206,6 @@ public function testProcessWithIdParameter() {
   /**
    * Tests interface validation in non-production environment.
    *
-   * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
    * @covers ::process
    */
   public function testProcessInterfaceMismatch() {
@@ -226,6 +224,7 @@ public function testProcessInterfaceMismatch() {
       ]);
 
     $handler_pass = new TaggedHandlersPass();
+    $this->setExpectedException(LogicException::class);
     $handler_pass->process($container);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
index 4a6eae7..4020b88 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
@@ -35,43 +35,39 @@ public function testSet() {
 
   /**
    * @covers ::set
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage Service ID names must be lowercase: Bar
    */
   public function testSetException() {
     $container = new ContainerBuilder();
     $class = new BarClass();
+    $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar');
     $container->set('Bar', $class);
     $this->assertNotEquals('bar', $class->_serviceId);
   }
 
   /**
    * @covers ::setParameter
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage Parameter names must be lowercase: Buzz
    */
   public function testSetParameterException() {
     $container = new ContainerBuilder();
+    $this->setExpectedException(\InvalidArgumentException::class, 'Parameter names must be lowercase: Buzz');
     $container->setParameter('Buzz', 'buzz');
   }
 
   /**
    * @covers ::register
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage Service ID names must be lowercase: Bar
    */
   public function testRegisterException() {
     $container = new ContainerBuilder();
+    $this->setExpectedException(\InvalidArgumentException::class, 'Service ID names must be lowercase: Bar');
     $container->register('Bar');
   }
 
   /**
    * Tests serialization.
-   *
-   * @expectedException \AssertionError
    */
   public function testSerialize() {
     $container = new ContainerBuilder();
+    $this->setExpectedException(\AssertionError::class);
     serialize($container);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
index 0ae5dd5..46f00bd 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
@@ -14,11 +14,10 @@ class ContainerTest extends UnitTestCase {
 
   /**
    * Tests serialization.
-   *
-   * @expectedException \AssertionError
    */
   public function testSerialize() {
     $container = new Container();
+    $this->setExpectedException(\AssertionError::class);
     serialize($container);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php
index 55c9bea..2ff6ebf 100644
--- a/core/tests/Drupal/Tests/Core/DrupalTest.php
+++ b/core/tests/Drupal/Tests/Core/DrupalTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Core;
 
+use Drupal\Core\DependencyInjection\ContainerNotInitializedException;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\Query\QueryAggregateInterface;
@@ -47,11 +48,9 @@ public function testSetContainer() {
 
   /**
    * @covers ::getContainer
-   *
-   * @expectedException \Drupal\Core\DependencyInjection\ContainerNotInitializedException
-   * @expectedExceptionMessage \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.
    */
   public function testGetContainerException() {
+    $this->setExpectedException(ContainerNotInitializedException::class, '\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.');
     \Drupal::getContainer();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
index f7a9851..3a7b3c1 100644
--- a/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/BaseFieldDefinitionTest.php
@@ -313,11 +313,11 @@ public function testDefaultValueCallback() {
    * Tests invalid default value callbacks.
    *
    * @covers ::setDefaultValueCallback
-   * @expectedException \InvalidArgumentException
    */
   public function testInvalidDefaultValueCallback() {
     $definition = BaseFieldDefinition::create($this->fieldType);
     // setDefaultValueCallback returns $this.
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->assertSame($definition,
       $definition->setDefaultValueCallback([get_class($this), 'mockDefaultValueCallback'])
     );
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
index b765af8..8ab7950 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -358,9 +358,6 @@ public function testValidate() {
    * @covers ::setValidationRequired
    * @covers ::save
    * @covers ::preSave
-   *
-   * @expectedException \LogicException
-   * @expectedExceptionMessage Entity validation was skipped.
    */
   public function testRequiredValidation() {
     $validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
@@ -405,6 +402,7 @@ public function testRequiredValidation() {
     // that trying to save a non-validated entity when validation is required
     // results in an exception.
     $this->assertTrue($this->entity->isValidationRequired());
+    $this->setExpectedException(\LogicException::class, 'Entity validation was skipped.');
     $this->entity->save();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
index 19c5604..4985470 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
@@ -310,9 +310,6 @@ public function providerTestGetBaseFieldDefinitionsTranslatableEntityTypeDefault
    * @covers ::getBaseFieldDefinitions
    * @covers ::buildBaseFieldDefinitions
    *
-   * @expectedException \LogicException
-   * @expectedExceptionMessage The Test entity type cannot be translatable as it does not define a translatable "langcode" field.
-   *
    * @dataProvider providerTestGetBaseFieldDefinitionsTranslatableEntityTypeLangcode
    */
   public function testGetBaseFieldDefinitionsTranslatableEntityTypeLangcode($provide_key, $provide_field, $translatable) {
@@ -333,6 +330,7 @@ public function testGetBaseFieldDefinitionsTranslatableEntityTypeLangcode($provi
     $this->entityType->isTranslatable()->willReturn(TRUE);
     $this->entityType->getLabel()->willReturn('Test');
 
+    $this->setExpectedException(\LogicException::class, 'The Test entity type cannot be translatable as it does not define a translatable "langcode" field.');
     $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type');
   }
 
@@ -452,8 +450,6 @@ public function testGetFieldStorageDefinitionsWithCaching() {
    *
    * @covers ::getBaseFieldDefinitions
    * @covers ::buildBaseFieldDefinitions
-   *
-   * @expectedException \LogicException
    */
   public function testGetBaseFieldDefinitionsInvalidDefinition() {
     $this->setUpEntityWithFieldDefinition(FALSE, 'langcode', ['langcode' => 'langcode']);
@@ -461,6 +457,7 @@ public function testGetBaseFieldDefinitionsInvalidDefinition() {
     $this->entityType->isTranslatable()->willReturn(TRUE);
     $this->entityType->getLabel()->willReturn('the_label');
 
+    $this->setExpectedException(\LogicException::class);
     $this->entityFieldManager->getBaseFieldDefinitions('test_entity_type');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
index 43464d1..4e2a79f1 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Entity;
 
 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
+use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
@@ -17,6 +18,7 @@
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\EntityTypeManager;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Entity\Exception\InvalidLinkTemplateException;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\Tests\UnitTestCase;
@@ -249,14 +251,13 @@ public function testGetFormObject() {
    * Tests the getFormObject() method with an invalid operation.
    *
    * @covers ::getFormObject
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
    */
   public function testGetFormObjectInvalidOperation() {
     $entity = $this->prophesize(EntityTypeInterface::class);
     $entity->getFormClass('edit')->willReturn('');
     $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]);
 
+    $this->setExpectedException(InvalidPluginDefinitionException::class);
     $this->entityTypeManager->getFormObject('test_entity_type', 'edit');
   }
 
@@ -284,13 +285,12 @@ public function testGetHandler() {
    * Tests the getHandler() method when no controller is defined.
    *
    * @covers ::getHandler
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
    */
   public function testGetHandlerMissingHandler() {
     $entity = $this->prophesize(EntityTypeInterface::class);
     $entity->getHandlerClass('storage')->willReturn('');
     $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]);
+    $this->setExpectedException(InvalidPluginDefinitionException::class);
     $this->entityTypeManager->getHandler('test_entity_type', 'storage');
   }
 
@@ -315,9 +315,6 @@ public function testGetRouteProviders() {
    * Tests the processDefinition() method.
    *
    * @covers ::processDefinition
-   *
-   * @expectedException \Drupal\Core\Entity\Exception\InvalidLinkTemplateException
-   * @expectedExceptionMessage Link template 'canonical' for entity type 'apple' must start with a leading slash, the current link template is 'path/to/apple'
    */
   public function testProcessDefinition() {
     $apple = $this->prophesize(EntityTypeInterface::class);
@@ -326,6 +323,7 @@ public function testProcessDefinition() {
     $apple->getLinkTemplates()->willReturn(['canonical' => 'path/to/apple']);
 
     $definition = $apple->reveal();
+    $this->setExpectedException(InvalidLinkTemplateException::class, "Link template 'canonical' for entity type 'apple' must start with a leading slash, the current link template is 'path/to/apple'");
     $this->entityTypeManager->processDefinition($definition, 'apple');
   }
 
@@ -371,13 +369,11 @@ public function providerTestGetDefinition() {
    * Tests the getDefinition() method with an invalid definition.
    *
    * @covers ::getDefinition
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
-   * @expectedExceptionMessage The "pear" entity type does not exist.
    */
   public function testGetDefinitionInvalidException() {
     $this->setUpEntityTypeDefinitions();
 
+    $this->setExpectedException(PluginNotFoundException::class, 'The "pear" entity type does not exist.');
     $this->entityTypeManager->getDefinition('pear', TRUE);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php
index 3761e0d..5b37291 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeRepositoryTest.php
@@ -7,6 +7,8 @@
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\EntityTypeRepository;
+use Drupal\Core\Entity\Exception\AmbiguousEntityClassException;
+use Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException;
 use Drupal\Tests\UnitTestCase;
 use Prophecy\Argument;
 
@@ -130,9 +132,6 @@ public function testGetEntityTypeFromClass() {
 
   /**
    * @covers ::getEntityTypeFromClass
-   *
-   * @expectedException \Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException
-   * @expectedExceptionMessage The \Drupal\pear\Entity\Pear class does not correspond to an entity type.
    */
   public function testGetEntityTypeFromClassNoMatch() {
     $apple = $this->prophesize(EntityTypeInterface::class);
@@ -146,14 +145,12 @@ public function testGetEntityTypeFromClassNoMatch() {
     $apple->getOriginalClass()->willReturn('\Drupal\apple\Entity\Apple');
     $banana->getOriginalClass()->willReturn('\Drupal\banana\Entity\Banana');
 
+    $this->setExpectedException(NoCorrespondingEntityClassException::class, 'The \Drupal\pear\Entity\Pear class does not correspond to an entity type.');
     $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\pear\Entity\Pear');
   }
 
   /**
    * @covers ::getEntityTypeFromClass
-   *
-   * @expectedException \Drupal\Core\Entity\Exception\AmbiguousEntityClassException
-   * @expectedExceptionMessage Multiple entity types found for \Drupal\apple\Entity\Apple.
    */
   public function testGetEntityTypeFromClassAmbiguous() {
     $boskoop = $this->prophesize(EntityTypeInterface::class);
@@ -169,6 +166,7 @@ public function testGetEntityTypeFromClassAmbiguous() {
       'gala' => $gala,
     ]);
 
+    $this->setExpectedException(AmbiguousEntityClassException::class, 'Multiple entity types found for \Drupal\apple\Entity\Apple.');
     $this->entityTypeRepository->getEntityTypeFromClass('\Drupal\apple\Entity\Apple');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
index 6668f1b..d1045f5 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php
@@ -400,11 +400,10 @@ protected function getTestHandlerClass() {
 
   /**
    * @covers ::setLinkTemplate
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testSetLinkTemplateWithInvalidPath() {
     $entity_type = $this->setUpEntityType(['id' => $this->randomMachineName()]);
+    $this->setExpectedException(\InvalidArgumentException::class);
     $entity_type->setLinkTemplate('test', 'invalid-path');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
index 4942701..d690f2a 100644
--- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@@ -5,6 +5,8 @@
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityMalformedException;
+use Drupal\Core\Entity\EntityStorageException;
 use Drupal\Core\Language\Language;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage;
@@ -439,14 +441,12 @@ public function testSaveContentEntity() {
   /**
    * @covers ::save
    * @covers ::doSave
-   *
-   * @expectedException \Drupal\Core\Entity\EntityMalformedException
-   * @expectedExceptionMessage The entity does not have an ID.
    */
   public function testSaveInvalid() {
     $this->setUpKeyValueEntityStorage();
 
     $entity = $this->getMockEntity('Drupal\Core\Config\Entity\ConfigEntityBase');
+    $this->setExpectedException(EntityMalformedException::class, 'The entity does not have an ID.');
     $this->entityStorage->save($entity);
     $this->keyValueStore->expects($this->never())
       ->method('has');
@@ -459,9 +459,6 @@ public function testSaveInvalid() {
   /**
    * @covers ::save
    * @covers ::doSave
-   *
-   * @expectedException \Drupal\Core\Entity\EntityStorageException
-   * @expectedExceptionMessage 'test_entity_type' entity with ID 'foo' already exists
    */
   public function testSaveDuplicate() {
     $this->setUpKeyValueEntityStorage();
@@ -475,6 +472,7 @@ public function testSaveDuplicate() {
       ->method('set');
     $this->keyValueStore->expects($this->never())
       ->method('delete');
+    $this->setExpectedException(EntityStorageException::class, "'test_entity_type' entity with ID 'foo' already exists");
     $this->entityStorage->save($entity);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php b/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php
index 22c606d..850e4b4 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Query/Sql/QueryTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Entity\EntityType;
 use Drupal\Tests\UnitTestCase;
+use Drupal\Core\Entity\Query\QueryException;
 use Drupal\Core\Entity\Query\Sql\Query;
 
 /**
@@ -36,11 +37,9 @@ protected function setUp() {
    * Tests entity query for entity type without base table.
    *
    * @covers ::prepare
-   *
-   * @expectedException \Drupal\Core\Entity\Query\QueryException
-   * @expectedExceptionMessage No base table for example_entity_query, invalid query.
    */
   public function testNoBaseTable() {
+    $this->setExpectedException(QueryException::class, 'No base table for example_entity_query, invalid query.');
     $this->query->execute();
   }
 
@@ -48,11 +47,9 @@ public function testNoBaseTable() {
    * Tests revision entity query for entity type without revision table.
    *
    * @covers ::prepare
-   *
-   * @expectedException \Drupal\Core\Entity\Query\QueryException
-   * @expectedExceptionMessage No revision table for example_entity_query, invalid query.
    */
   public function testNoRevisionTable() {
+    $this->setExpectedException(QueryException::class, 'No revision table for example_entity_query, invalid query.');
     $this->query->allRevisions()->execute();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php
index 8ce420b..39c9a05 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Core\Entity\Sql;
 
 use Drupal\Core\Entity\Sql\DefaultTableMapping;
+use Drupal\Core\Entity\Sql\SqlContentEntityStorageException;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -294,9 +295,6 @@ public function testGetFieldColumnName($base_field, $columns, $column, $expected
    * @param string $column
    *   The name of the column to be processed.
    *
-   * @expectedException \Drupal\Core\Entity\Sql\SqlContentEntityStorageException
-   * @expectedExceptionMessage Column information not available for the 'test' field.
-   *
    * @covers ::getFieldColumnName
    *
    * @dataProvider providerTestGetFieldColumnName
@@ -310,6 +308,7 @@ public function testGetFieldColumnNameInvalid($base_field, $columns, $column) {
       ->willReturn(TRUE);
 
     $table_mapping = new DefaultTableMapping($this->entityType, $definitions);
+    $this->setExpectedException(SqlContentEntityStorageException::class, "Column information not available for the 'test' field.");
     $table_mapping->getFieldColumnName($definitions['test'], $column);
   }
 
@@ -440,13 +439,11 @@ public function providerTestGetFieldTableName() {
   /**
    * Tests DefaultTableMapping::getFieldTableName() with an invalid parameter.
    *
-   * @expectedException \Drupal\Core\Entity\Sql\SqlContentEntityStorageException
-   * @expectedExceptionMessage Table information not available for the 'invalid_field_name' field.
-   *
    * @covers ::getFieldTableName
    */
   public function testGetFieldTableNameInvalid() {
     $table_mapping = new DefaultTableMapping($this->entityType, []);
+    $this->setExpectedException(SqlContentEntityStorageException::class, "Table information not available for the 'invalid_field_name' field.");
     $table_mapping->getFieldTableName('invalid_field_name');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
index e290f5a..953daac 100644
--- a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
@@ -6,6 +6,7 @@
 use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\TypedData\Exception\MissingDataException;
 use Drupal\Core\TypedData\TypedDataManagerInterface;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\Language\Language;
@@ -275,18 +276,18 @@ public function testGet() {
 
   /**
    * @covers ::get
-   * @expectedException \InvalidArgumentException
    */
   public function testGetInvalidField() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->entityAdapter->get('invalid');
   }
 
   /**
    * @covers ::get
-   * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException
    */
   public function testGetWithoutData() {
     $this->entityAdapter->setValue(NULL);
+    $this->setExpectedException(MissingDataException::class);
     $this->entityAdapter->get('id');
   }
 
@@ -305,11 +306,11 @@ public function testSet() {
 
   /**
    * @covers ::set
-   * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException
    */
   public function testSetWithoutData() {
     $this->entityAdapter->setValue(NULL);
     $id_items = [ ['value' => $this->id + 1] ];
+    $this->setExpectedException(MissingDataException::class);
     $this->entityAdapter->set('id', $id_items);
   }
 
@@ -335,10 +336,10 @@ public function testToArray() {
 
   /**
    * @covers ::toArray
-   * @expectedException \Drupal\Core\TypedData\Exception\MissingDataException
    */
   public function testToArrayWithoutData() {
     $this->entityAdapter->setValue(NULL);
+    $this->setExpectedException(MissingDataException::class);
     $this->entityAdapter->toArray();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
index 3f80e4d..6ac6cc1 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
@@ -115,8 +115,6 @@ public static function providerTestDestinationRedirect() {
 
   /**
    * @dataProvider providerTestDestinationRedirectToExternalUrl
-   *
-   * @expectedException \PHPUnit_Framework_Error
    */
   public function testDestinationRedirectToExternalUrl($request, $expected) {
     $dispatcher = new EventDispatcher();
@@ -126,6 +124,7 @@ public function testDestinationRedirectToExternalUrl($request, $expected) {
     $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
+    $this->setExpectedException(\PHPUnit_Framework_Error::class);
     $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
 
     $this->assertEquals(400, $event->getResponse()->getStatusCode());
@@ -165,8 +164,6 @@ public function providerTestDestinationRedirectToExternalUrl() {
   }
 
   /**
-   * @expectedException \PHPUnit_Framework_Error
-   *
    * @dataProvider providerTestDestinationRedirectWithInvalidUrl
    */
   public function testDestinationRedirectWithInvalidUrl(Request $request) {
@@ -177,6 +174,7 @@ public function testDestinationRedirectWithInvalidUrl(Request $request) {
     $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
     $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
     $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
+    $this->setExpectedException(\PHPUnit_Framework_Error::class);
     $dispatcher->dispatch(KernelEvents::RESPONSE, $event);
 
     $this->assertEquals(400, $event->getResponse()->getStatusCode());
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
index 55db07e..01a6f36 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php
@@ -89,9 +89,6 @@ public function testOnRouteBuildingValidVariables(Route $route) {
    *   The route to check.
    *
    * @dataProvider providerTestOnRouteBuildingInvalidVariables
-   * @expectedException \PHPUnit_Framework_Error_Warning
-   * @expectedExceptionMessage uses reserved variable names
-   *
    * @covers ::onAlterRoutes
    */
   public function testOnRouteBuildingInvalidVariables(Route $route) {
@@ -100,6 +97,7 @@ public function testOnRouteBuildingInvalidVariables(Route $route) {
 
     $event = new RouteBuildEvent($route_collection, 'test');
     $subscriber = new SpecialAttributesRouteSubscriber();
+    $this->setExpectedException(\PHPUnit_Framework_Error_Warning::class, 'uses reserved variable names');
     $subscriber->onAlterRoutes($event);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
index 74a7649..796a916 100644
--- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
@@ -50,9 +50,6 @@ public function testInfoParserNonExisting() {
    * Test if correct exception is thrown for a broken info file.
    *
    * @covers ::parse
-   *
-   * @expectedException \Drupal\Core\Extension\InfoParserException
-   * @expectedExceptionMessageRegExp #broken\.info\.txt#
    */
   public function testInfoParserBroken() {
     $broken_info = <<<BROKEN_INFO
@@ -74,6 +71,7 @@ public function testInfoParserBroken() {
       ],
     ]);
     $filename = vfsStream::url('modules/fixtures/broken.info.txt');
+    $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'broken.info.txt');
     $this->infoParser->parse($filename);
   }
 
@@ -81,9 +79,6 @@ public function testInfoParserBroken() {
    * Tests that missing required keys are detected.
    *
    * @covers ::parse
-   *
-   * @expectedException \Drupal\Core\Extension\InfoParserException
-   * @expectedExceptionMessageRegExp #Missing required keys \(type, core, name\) in .+?missing_keys\.info\.txt#
    */
   public function testInfoParserMissingKeys() {
     $missing_keys = <<<MISSINGKEYS
@@ -101,6 +96,7 @@ public function testInfoParserMissingKeys() {
       ],
     ]);
     $filename = vfsStream::url('modules/fixtures/missing_keys.info.txt');
+    $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type, core, name) in vfs://modules/fixtures/missing_keys.info.txt');
     $this->infoParser->parse($filename);
   }
 
@@ -108,9 +104,6 @@ public function testInfoParserMissingKeys() {
    * Tests that missing required key is detected.
    *
    * @covers ::parse
-   *
-   * @expectedException \Drupal\Core\Extension\InfoParserException
-   * @expectedExceptionMessageRegExp #Missing required keys \(type\) in .+?missing_key\.info\.txt#
    */
   public function testInfoParserMissingKey() {
     $missing_key = <<<MISSINGKEY
@@ -131,6 +124,7 @@ public function testInfoParserMissingKey() {
       ],
     ]);
     $filename = vfsStream::url('modules/fixtures/missing_key.info.txt');
+    $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt');
     $this->infoParser->parse($filename);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
index 42a76ba..1bde890 100644
--- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
@@ -146,10 +146,9 @@ public function testGetModuleWithExistingModule() {
 
   /**
    * @covers ::getModule
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testGetModuleWithNonExistingModule() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->moduleHandler->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php
index 18d270e..14e03cb 100644
--- a/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/ConfigFormBaseTraitTest.php
@@ -41,8 +41,6 @@ public function testConfig() {
 
   /**
    * @covers ::config
-   * @expectedException \LogicException
-   * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait
    */
   public function testConfigFactoryException() {
     $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait');
@@ -50,13 +48,12 @@ public function testConfigFactoryException() {
     $config_method->setAccessible(TRUE);
 
     // There is no config factory available this should result in an exception.
+    $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait');
     $config_method->invoke($trait, 'editable.config');
   }
 
   /**
    * @covers ::config
-   * @expectedException \LogicException
-   * @expectedExceptionMessage No config factory available for ConfigFormBaseTrait
    */
   public function testConfigFactoryExceptionInvalidProperty() {
     $trait = $this->getMockForTrait('Drupal\Core\Form\ConfigFormBaseTrait');
@@ -65,6 +62,7 @@ public function testConfigFactoryExceptionInvalidProperty() {
     $config_method->setAccessible(TRUE);
 
     // There is no config factory available this should result in an exception.
+    $this->setExpectedException(\LogicException::class, 'No config factory available for ConfigFormBaseTrait');
     $config_method->invoke($trait, 'editable.config');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php
index 067ba47..ce627359 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormAjaxResponseBuilderTest.php
@@ -9,6 +9,7 @@
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\HttpException;
 
 /**
  * @coversDefaultClass \Drupal\Core\Form\FormAjaxResponseBuilder
@@ -43,8 +44,6 @@ protected function setUp() {
 
   /**
    * @covers ::buildResponse
-   *
-   * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
    */
   public function testBuildResponseNoTriggeringElement() {
     $this->renderer->expects($this->never())
@@ -56,13 +55,12 @@ public function testBuildResponseNoTriggeringElement() {
     $commands = [];
 
     $expected = [];
+    $this->setExpectedException(HttpException::class);
     $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands));
   }
 
   /**
    * @covers ::buildResponse
-   *
-   * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
    */
   public function testBuildResponseNoCallable() {
     $this->renderer->expects($this->never())
@@ -76,6 +74,7 @@ public function testBuildResponseNoCallable() {
     $commands = [];
 
     $expected = [];
+    $this->setExpectedException(HttpException::class);
     $this->assertSame($expected, $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, $commands));
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
index 6159179..9958a8a 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
@@ -13,6 +13,7 @@
 use Drupal\Core\Cache\Context\CacheContextsManager;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Drupal\Core\Form\EnforcedResponseException;
+use Drupal\Core\Form\Exception\BrokenPostRequestException;
 use Drupal\Core\Form\FormBuilder;
 use Drupal\Core\Form\FormBuilderInterface;
 use Drupal\Core\Form\FormInterface;
@@ -52,15 +53,13 @@ protected function setUp() {
 
   /**
    * Tests the getFormId() method with a string based form ID.
-   *
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage The form argument foo is not a valid form.
    */
   public function testGetFormIdWithString() {
     $form_arg = 'foo';
 
     $clean_form_state = new FormState();
     $form_state = new FormState();
+    $this->setExpectedException(\InvalidArgumentException::class, 'The form argument foo is not a valid form.');
     $form_id = $this->formBuilder->getFormId($form_arg, $form_state);
 
     $this->assertSame($form_arg, $form_id);
@@ -218,14 +217,12 @@ public function testHandleRedirectWithResponse() {
 
   /**
    * Tests the getForm() method with a string based form ID.
-   *
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage The form argument test_form_id is not a valid form.
    */
   public function testGetFormWithString() {
     $form_id = 'test_form_id';
     $expected_form = $form_id();
 
+    $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.');
     $form = $this->formBuilder->getForm($form_id);
     $this->assertFormElement($expected_form, $form, 'test');
     $this->assertSame('test-form-id', $form['#id']);
@@ -262,14 +259,12 @@ public function testGetFormWithClassString() {
 
   /**
    * Tests the buildForm() method with a string based form ID.
-   *
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage The form argument test_form_id is not a valid form.
    */
   public function testBuildFormWithString() {
     $form_id = 'test_form_id';
     $expected_form = $form_id();
 
+    $this->setExpectedException(\InvalidArgumentException::class, 'The form argument test_form_id is not a valid form.');
     $form = $this->formBuilder->getForm($form_id);
     $this->assertFormElement($expected_form, $form, 'test');
     $this->assertArrayHasKey('#id', $form);
@@ -547,8 +542,6 @@ public function testFormCacheDeletionUncached() {
 
   /**
    * @covers ::buildForm
-   *
-   * @expectedException \Drupal\Core\Form\Exception\BrokenPostRequestException
    */
   public function testExceededFileSize() {
     $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]);
@@ -565,6 +558,7 @@ public function testExceededFileSize() {
     $form_arg = $this->getMockForm('test_form_id');
     $form_state = new FormState();
 
+    $this->setExpectedException(BrokenPostRequestException::class);
     $this->formBuilder->buildForm($form_arg, $form_state);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php
index 67e7a86..ff0bcd6 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php
@@ -158,10 +158,9 @@ public function testIsCached($cache) {
    * @dataProvider providerSingleBooleanArgument
    *
    * @param bool $cache
-   *
-   * @expectedException \LogicException
    */
   public function testSetCachedWithLogicException($cache) {
+    $this->setExpectedException(\LogicException::class);
     $this->decoratedFormState->setCached($cache)
       ->willThrow(\LogicException::class);
 
diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
index 0da2fe0..4017904 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
@@ -132,13 +132,11 @@ public function providerTestSetErrorByName() {
    * Tests that form errors during submission throw an exception.
    *
    * @covers ::setErrorByName
-   *
-   * @expectedException \LogicException
-   * @expectedExceptionMessage Form errors cannot be set after form validation has finished.
    */
   public function testFormErrorsDuringSubmission() {
     $form_state = new FormState();
     $form_state->setValidationComplete();
+    $this->setExpectedException(\LogicException::class, 'Form errors cannot be set after form validation has finished.');
     $form_state->setErrorByName('test', 'message');
   }
 
@@ -315,13 +313,11 @@ public function testSetCachedPost() {
 
   /**
    * @covers ::setCached
-   *
-   * @expectedException \LogicException
-   * @expectedExceptionMessage Form state caching on GET requests is not allowed.
    */
   public function testSetCachedGet() {
     $form_state = new FormState();
     $form_state->setRequestMethod('GET');
+    $this->setExpectedException(\LogicException::class, 'Form state caching on GET requests is not allowed.');
     $form_state->setCached();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php
index ec2ac8b..50124d0 100644
--- a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php
@@ -97,12 +97,11 @@ public function providerGetValues() {
    *
    * @dataProvider providerGetValuesBroken
    *
-   * @expectedException \UnexpectedValueException
-   *
    * @param string[] $parents
    * @param string $expected
    */
   public function testGetValuesBroken(array $parents, $expected) {
+    $this->setExpectedException(\UnexpectedValueException::class);
     $this->testGetValues($parents, $expected);
   }
 
@@ -161,10 +160,9 @@ public function providerTestGetValue() {
    * @covers ::getValue
    *
    * @dataProvider providerTestGetValueBroken
-   *
-   * @expectedException \UnexpectedValueException
    */
   public function testGetValueBroken(array $parents, $key, $expected, $default = NULL) {
+    $this->setExpectedException(\UnexpectedValueException::class);
     $this->testGetValue($parents, $key, $expected, $default);
   }
 
@@ -217,10 +215,9 @@ public function providerTestSetValues() {
    * @covers ::setValues
    *
    * @dataProvider providerTestSetValuesBroken
-   *
-   * @expectedException \UnexpectedValueException
    */
   public function testSetValuesBroken($parents, $new_values, $expected) {
+    $this->setExpectedException(\UnexpectedValueException::class);
     $this->testSetValues($parents, $new_values, $expected);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
index 92caa26..bebc935 100644
--- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Core\Menu;
 
+use Drupal\Component\Plugin\Exception\PluginException;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Language\Language;
 use Drupal\Core\Menu\ContextualLinkDefault;
@@ -204,8 +205,6 @@ public function testGetContextualLinkPluginsByGroupWithCache() {
    * Tests processDefinition() by passing a plugin definition without a route.
    *
    * @see \Drupal\Core\Menu\ContextualLinkManager::processDefinition()
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
    */
   public function testProcessDefinitionWithoutRoute() {
     $definition = [
@@ -213,6 +212,7 @@ public function testProcessDefinitionWithoutRoute() {
       'group' => 'example',
       'id' => 'test_plugin',
     ];
+    $this->setExpectedException(PluginException::class);
     $this->contextualLinkManager->processDefinition($definition, 'test_plugin');
   }
 
@@ -220,8 +220,6 @@ public function testProcessDefinitionWithoutRoute() {
    * Tests processDefinition() by passing a plugin definition without a group.
    *
    * @see \Drupal\Core\Menu\ContextualLinkManager::processDefinition()
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
    */
   public function testProcessDefinitionWithoutGroup() {
     $definition = [
@@ -229,6 +227,7 @@ public function testProcessDefinitionWithoutGroup() {
       'route_name' => 'example',
       'id' => 'test_plugin',
     ];
+    $this->setExpectedException(PluginException::class);
     $this->contextualLinkManager->processDefinition($definition, 'test_plugin');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php
index 82a65818..67e99de 100644
--- a/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php
+++ b/core/tests/Drupal/Tests/Core/PageCache/ChainRequestPolicyTest.php
@@ -63,7 +63,6 @@ public function testNullRuleChain() {
   /**
    * Asserts that check() throws an exception if a rule returns an invalid value.
    *
-   * @expectedException \UnexpectedValueException
    * @dataProvider providerChainExceptionOnInvalidReturnValue
    * @covers ::check
    */
@@ -76,6 +75,7 @@ public function testChainExceptionOnInvalidReturnValue($return_value) {
 
     $this->policy->addPolicy($rule);
 
+    $this->setExpectedException(\UnexpectedValueException::class);
     $this->policy->check($this->request);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php
index 1575ac1..902d646 100644
--- a/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php
+++ b/core/tests/Drupal/Tests/Core/PageCache/ChainResponsePolicyTest.php
@@ -72,7 +72,6 @@ public function testNullRuleChain() {
   /**
    * Asserts that check() throws an exception if a rule returns an invalid value.
    *
-   * @expectedException \UnexpectedValueException
    * @dataProvider providerChainExceptionOnInvalidReturnValue
    * @covers ::check
    */
@@ -85,6 +84,7 @@ public function testChainExceptionOnInvalidReturnValue($return_value) {
 
     $this->policy->addPolicy($rule);
 
+    $this->setExpectedException(\UnexpectedValueException::class);
     $actual_result = $this->policy->check($this->response, $this->request);
     $this->assertSame(NULL, $actual_result);
   }
diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php
index ebafab0..67decbe 100644
--- a/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php
+++ b/core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
 use Drupal\Core\ParamConverter\EntityConverter;
+use Drupal\Core\ParamConverter\ParamNotConvertedException;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\Routing\Route;
 
@@ -110,8 +111,6 @@ public function providerTestConvert() {
 
   /**
    * Tests the convert() method with an invalid entity type.
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
    */
   public function testConvertWithInvalidEntityType() {
     $this->entityManager->expects($this->once())
@@ -119,16 +118,15 @@ public function testConvertWithInvalidEntityType() {
       ->with('invalid_id')
       ->willThrowException(new InvalidPluginDefinitionException('invalid_id'));
 
+    $this->setExpectedException(InvalidPluginDefinitionException::class);
     $this->entityConverter->convert('id', ['type' => 'entity:invalid_id'], 'foo', ['foo' => 'id']);
   }
 
   /**
    * Tests the convert() method with an invalid dynamic entity type.
-   *
-   * @expectedException \Drupal\Core\ParamConverter\ParamNotConvertedException
-   * @expectedExceptionMessage The "foo" parameter was not converted because the "invalid_id" parameter is missing
    */
   public function testConvertWithInvalidDynamicEntityType() {
+    $this->setExpectedException(ParamNotConvertedException::class, 'The "foo" parameter was not converted because the "invalid_id" parameter is missing');
     $this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php
index 1c85cf6..6d60e1d 100644
--- a/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Core\ParamConverter;
 
 use Drupal\Core\ParamConverter\ParamConverterManager;
+use Drupal\Core\ParamConverter\ParamNotConvertedException;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 use Symfony\Component\Routing\Route;
@@ -51,10 +52,9 @@ public function testGetConverter($name, $class) {
    * Tests \Drupal\Core\ParamConverter\ParamConverterManager::getConverter().
    *
    * @covers ::getConverter
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testGetConverterException() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->manager->getConverter('undefined.converter');
   }
 
@@ -220,9 +220,6 @@ public function testConvertNoConverting() {
 
   /**
    * @covers ::convert
-   *
-   * @expectedException \Drupal\Core\ParamConverter\ParamNotConvertedException
-   * @expectedExceptionMessage The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")
    */
   public function testConvertMissingParam() {
     $route = new Route('/test/{id}');
@@ -246,6 +243,7 @@ public function testConvertMissingParam() {
       ->will($this->returnValue(NULL));
     $this->manager->addConverter($converter, 'test_convert');
 
+    $this->setExpectedException(ParamNotConvertedException::class, 'The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")');
     $this->manager->convert($defaults);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php
index 4076f1e..586259d 100644
--- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php
+++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorFrontTest.php
@@ -7,6 +7,7 @@
 use Drupal\Core\PathProcessor\PathProcessorFront;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 
 /**
  * Test front page path processing.
@@ -47,7 +48,6 @@ public function providerProcessInbound() {
    * Test inbound failure with broken config.
    *
    * @covers ::processInbound
-   * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
    */
   public function testProcessInboundBadConfig() {
     $config_factory = $this->prophesize(ConfigFactoryInterface::class);
@@ -57,6 +57,7 @@ public function testProcessInboundBadConfig() {
     $config->get('page.front')
       ->willReturn('');
     $processor = new PathProcessorFront($config_factory->reveal());
+    $this->setExpectedException(NotFoundHttpException::class);
     $processor->processInbound('/', new Request());
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
index 8d9cc52..58f61d1 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
@@ -107,7 +107,6 @@ public function testGetDataDefinition($is_multiple) {
   }
 
   /**
-   * @expectedException \Exception
    * @dataProvider providerGetDataDefinition
    * @covers ::getDataDefinition
    * @uses \Drupal
@@ -155,6 +154,7 @@ public function testGetDataDefinitionInvalidType($is_multiple) {
       ->method('getDataType')
       ->willReturn($data_type);
 
+    $this->setExpectedException(\Exception::class);
     $this->assertSame(
       $mock_data_definition,
       $mock_context_definition->getDataDefinition()
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
index 02fea32..6fe21c1 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Context/LazyContextRepositoryTest.php
@@ -66,11 +66,10 @@ public function testGetRuntimeMultipleContextProviders() {
 
   /**
    * @covers ::getRuntimeContexts
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.
    */
   public function testInvalidContextId() {
     $lazy_context_repository = new LazyContextRepository($this->container, ['test_provider']);
+    $this->setExpectedException(\InvalidArgumentException::class, 'You must provide the context IDs in the @{service_id}:{unqualified_context_id} format.');
     $lazy_context_repository->getRuntimeContexts(['test_context', '@test_provider:test_context1']);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php
index b0b43bb..4ed5e6e 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Plugin;
 
 use Drupal\Component\Plugin\ConfigurablePluginInterface;
+use Drupal\Component\Plugin\Exception\ContextException;
 use Drupal\Core\Plugin\Context\ContextDefinition;
 use Drupal\Core\Plugin\Context\ContextHandler;
 use Drupal\Core\Plugin\ContextAwarePluginInterface;
@@ -279,9 +280,6 @@ public function testApplyContextMapping() {
 
   /**
    * @covers ::applyContextMapping
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\ContextException
-   * @expectedExceptionMessage Required contexts without a value: hit.
    */
   public function testApplyContextMappingMissingRequired() {
     $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
@@ -311,6 +309,7 @@ public function testApplyContextMappingMissingRequired() {
     $plugin->expects($this->never())
       ->method('getContext');
 
+    $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.');
     $this->contextHandler->applyContextMapping($plugin, $contexts);
   }
 
@@ -350,9 +349,6 @@ public function testApplyContextMappingMissingNotRequired() {
 
   /**
    * @covers ::applyContextMapping
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\ContextException
-   * @expectedExceptionMessage Required contexts without a value: hit.
    */
   public function testApplyContextMappingNoValueRequired() {
     $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
@@ -381,6 +377,7 @@ public function testApplyContextMappingNoValueRequired() {
     $plugin->expects($this->never())
       ->method('setContextValue');
 
+    $this->setExpectedException(ContextException::class, 'Required contexts without a value: hit.');
     $this->contextHandler->applyContextMapping($plugin, $contexts);
   }
 
@@ -464,9 +461,6 @@ public function testApplyContextMappingConfigurableAssigned() {
 
   /**
    * @covers ::applyContextMapping
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\ContextException
-   * @expectedExceptionMessage Assigned contexts were not satisfied: miss
    */
   public function testApplyContextMappingConfigurableAssignedMiss() {
     $context = $this->getMock('Drupal\Core\Plugin\Context\ContextInterface');
@@ -489,6 +483,7 @@ public function testApplyContextMappingConfigurableAssignedMiss() {
     $plugin->expects($this->never())
       ->method('setContextValue');
 
+    $this->setExpectedException(ContextException::class, 'Assigned contexts were not satisfied: miss');
     $this->contextHandler->applyContextMapping($plugin, $contexts, ['miss' => 'name']);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php
index 11efd48..01b7cd1 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Core\Plugin;
 
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
 use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin;
 
 /**
@@ -43,11 +44,10 @@ public function testGet() {
 
   /**
    * @covers ::get
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
-   * @expectedExceptionMessage Plugin ID 'pear' was not found.
    */
   public function testGetNotExistingPlugin() {
     $this->setupPluginCollection();
+    $this->setExpectedException(PluginNotFoundException::class, "Plugin ID 'pear' was not found.");
     $this->defaultPluginCollection->get('pear');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php
index 7e2842e..c65de35 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Core\Plugin;
 
 use Drupal\Component\Plugin\Definition\PluginDefinition;
+use Drupal\Component\Plugin\Exception\PluginException;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Plugin\PluginFormInterface;
@@ -271,9 +272,6 @@ public function testCreateInstanceWithJustValidInterfaces() {
    * Tests plugins without the proper interface.
    *
    * @covers ::createInstance
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginException
-   * @expectedExceptionMessage Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface
    */
   public function testCreateInstanceWithInvalidInterfaces() {
     $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
@@ -294,6 +292,7 @@ public function testCreateInstanceWithInvalidInterfaces() {
     $this->expectedDefinitions['banana']['provider'] = 'plugin_test';
 
     $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler, NULL, '\Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface');
+    $this->setExpectedException(PluginException::class, 'Plugin "kale" (Drupal\plugin_test\Plugin\plugin_test\fruit\Kale) must implement interface \Drupal\plugin_test\Plugin\plugin_test\fruit\FruitInterface');
     $plugin_manager->createInstance('kale');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php
index 81e7d56..e4ea645 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php
@@ -134,9 +134,6 @@ public function testGetDeriverClassWithInvalidClassedDefinitions() {
    * Tests the getDerivativeFetcher method with a non-existent class.
    *
    * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException
-   * @expectedExceptionMessage Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.
    */
   public function testNonExistentDerivativeFetcher() {
     $definitions = [];
@@ -150,6 +147,7 @@ public function testNonExistentDerivativeFetcher() {
       ->will($this->returnValue($definitions));
 
     $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
+    $this->setExpectedException(InvalidDeriverException::class, 'Plugin (non_existent_discovery) deriver "\Drupal\system\Tests\Plugin\NonExistentDeriver" does not exist.');
     $discovery->getDefinitions();
   }
 
@@ -157,9 +155,6 @@ public function testNonExistentDerivativeFetcher() {
    * Tests the getDerivativeFetcher method with an invalid class.
    *
    * @see \Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator::getDeriver().\
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\InvalidDeriverException
-   * @expectedExceptionMessage Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.
    */
   public function testInvalidDerivativeFetcher() {
     $definitions = [];
@@ -173,6 +168,7 @@ public function testInvalidDerivativeFetcher() {
       ->will($this->returnValue($definitions));
 
     $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
+    $this->setExpectedException(InvalidDeriverException::class, 'Plugin (invalid_discovery) deriver "\Drupal\KernelTests\Core\Plugin\DerivativeTest" must implement \Drupal\Component\Plugin\Derivative\DeriverInterface.');
     $discovery->getDefinitions();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php
index ab65ab7..9f4eb95 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/HookDiscoveryTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\Core\Plugin\Discovery;
 
+use Drupal\Component\Plugin\Exception\PluginNotFoundException;
 use Drupal\Core\Plugin\Discovery\HookDiscovery;
 use Drupal\Tests\UnitTestCase;
 
@@ -118,14 +119,13 @@ public function testGetDefinition() {
    * Tests the getDefinition method with an unknown plugin ID.
    *
    * @see \Drupal\Core\Plugin\Discovery::getDefinition()
-   *
-   * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException
    */
   public function testGetDefinitionWithUnknownID() {
     $this->moduleHandler->expects($this->once())
       ->method('getImplementations')
       ->will($this->returnValue([]));
 
+    $this->setExpectedException(PluginNotFoundException::class);
     $this->hookDiscovery->getDefinition('test_non_existant', TRUE);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
index b9f86ac..d168f74 100644
--- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php
@@ -101,14 +101,12 @@ public function testChildren() {
 
   /**
    * Tests the children() method with an invalid key.
-   *
-   * @expectedException \PHPUnit_Framework_Error
-   * @expectedExceptionMessage "foo" is an invalid render array key
    */
   public function testInvalidChildren() {
     $element = [
       'foo' => 'bar',
     ];
+    $this->setExpectedException(\PHPUnit_Framework_Error::class, '"foo" is an invalid render array key');
     Element::children($element);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php
index fc90e5d..776b794 100644
--- a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php
@@ -120,9 +120,6 @@ public function providerProcessPlaceholders() {
 
   /**
    * @covers ::processPlaceholders
-   *
-   * @expectedException \AssertionError
-   * @expectedExceptionMessage At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.
    */
   public function testProcessPlaceholdersNoStrategies() {
     // Placeholders but no strategies defined.
@@ -131,14 +128,12 @@ public function testProcessPlaceholdersNoStrategies() {
     ];
 
     $chained_placeholder_strategy = new ChainedPlaceholderStrategy();
+    $this->setExpectedException(\AssertionError::class, 'At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.');
     $chained_placeholder_strategy->processPlaceholders($placeholders);
   }
 
   /**
    * @covers ::processPlaceholders
-   *
-   * @expectedException \AssertionError
-   * @expectedExceptionMessage Processed placeholders must be a subset of all placeholders.
    */
   public function testProcessPlaceholdersWithRoguePlaceholderStrategy() {
     // Placeholders but no strategies defined.
@@ -157,6 +152,7 @@ public function testProcessPlaceholdersWithRoguePlaceholderStrategy() {
 
     $chained_placeholder_strategy = new ChainedPlaceholderStrategy();
     $chained_placeholder_strategy->addPlaceholderStrategy($rogue_strategy);
+    $this->setExpectedException(\AssertionError::class, 'Processed placeholders must be a subset of all placeholders.');
     $chained_placeholder_strategy->processPlaceholders($placeholders);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
index bb929bd..3e1ee40 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
@@ -571,9 +571,6 @@ public function providerTestBubblingWithPrerender() {
 
   /**
    * Tests that an element's cache keys cannot be changed during its rendering.
-   *
-   * @expectedException \LogicException
-   * @expectedExceptionMessage Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.
    */
   public function testOverWriteCacheKeys() {
     $this->setUpRequest();
@@ -586,6 +583,7 @@ public function testOverWriteCacheKeys() {
        ],
       '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingCacheOverwritePrerender'],
     ];
+    $this->setExpectedException(\LogicException::class, 'Cache keys may not be changed after initial setup. Use the contexts property instead to bubble additional metadata.');
     $this->renderer->renderRoot($data);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
index 12ab955..00426c2 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
@@ -847,28 +847,24 @@ public function testRecursivePlaceholder() {
   /**
    * @covers ::render
    * @covers ::doRender
-   *
-   * @expectedException \DomainException
-   * @expectedExceptionMessage The #lazy_builder property must have an array as a value.
    */
   public function testInvalidLazyBuilder() {
     $element = [];
     $element['#lazy_builder'] = '\Drupal\Tests\Core\Render\PlaceholdersTest::callback';
 
+    $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value.');
     $this->renderer->renderRoot($element);
   }
 
   /**
    * @covers ::render
    * @covers ::doRender
-   *
-   * @expectedException \DomainException
-   * @expectedExceptionMessage The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.
    */
   public function testInvalidLazyBuilderArguments() {
     $element = [];
     $element['#lazy_builder'] = ['\Drupal\Tests\Core\Render\PlaceholdersTest::callback', 'arg1', 'arg2'];
 
+    $this->setExpectedException(\DomainException::class, 'The #lazy_builder property must have an array as a value, containing two values: the callback, and the arguments for the callback.');
     $this->renderer->renderRoot($element);
   }
 
@@ -896,9 +892,6 @@ public function testScalarLazybuilderCallbackContext() {
   /**
    * @covers ::render
    * @covers ::doRender
-   *
-   * @expectedException \DomainException
-   * @expectedExceptionMessage A #lazy_builder callback's context may only contain scalar values or NULL.
    */
   public function testNonScalarLazybuilderCallbackContext() {
     $element = [];
@@ -912,15 +905,13 @@ public function testNonScalarLazybuilderCallbackContext() {
       'array' => ['hi!'],
     ]];
 
+    $this->setExpectedException(\DomainException::class, "A #lazy_builder callback's context may only contain scalar values or NULL.");
     $this->renderer->renderRoot($element);
   }
 
   /**
    * @covers ::render
    * @covers ::doRender
-   *
-   * @expectedException \DomainException
-   * @expectedExceptionMessage When a #lazy_builder callback is specified, no children can exist; all children must be generated by the #lazy_builder callback. You specified the following children: child_a, child_b.
    */
   public function testChildrenPlusBuilder() {
     $element = [];
@@ -928,15 +919,13 @@ public function testChildrenPlusBuilder() {
     $element['child_a']['#markup'] = 'Oh hai!';
     $element['child_b']['#markup'] = 'kthxbai';
 
+    $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no children can exist; all children must be generated by the #lazy_builder callback. You specified the following children: child_a, child_b.');
     $this->renderer->renderRoot($element);
   }
 
   /**
    * @covers ::render
    * @covers ::doRender
-   *
-   * @expectedException \DomainException
-   * @expectedExceptionMessage When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #llama, #piglet.
    */
   public function testPropertiesPlusBuilder() {
     $element = [];
@@ -944,20 +933,19 @@ public function testPropertiesPlusBuilder() {
     $element['#llama'] = '#awesome';
     $element['#piglet'] = '#cute';
 
+    $this->setExpectedException(\DomainException::class, 'When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #llama, #piglet.');
     $this->renderer->renderRoot($element);
   }
 
   /**
    * @covers ::render
    * @covers ::doRender
-   *
-   * @expectedException \LogicException
-   * @expectedExceptionMessage When #create_placeholder is set, a #lazy_builder callback must be present as well.
    */
   public function testCreatePlaceholderPropertyWithoutLazyBuilder() {
     $element = [];
     $element['#create_placeholder'] = TRUE;
 
+    $this->setExpectedException(\LogicException::class, 'When #create_placeholder is set, a #lazy_builder callback must be present as well.');
     $this->renderer->renderRoot($element);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
index bffbd22..76f9d48 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
@@ -31,8 +31,6 @@ protected function setUpRenderRecursionComplexElements() {
    * @covers ::renderRoot
    * @covers ::render
    * @covers ::doRender
-   *
-   * @expectedException \LogicException
    */
   public function testRenderRecursionWithNestedRenderRoot() {
     list($complex_child_markup, $parent_markup, $complex_child_template) = $this->setUpRenderRecursionComplexElements();
@@ -41,6 +39,7 @@ public function testRenderRecursionWithNestedRenderRoot() {
 
     $complex_child = $complex_child_template;
     $callable = function () use ($renderer, $complex_child) {
+      $this->setExpectedException(\LogicException::class);
       $renderer->renderRoot($complex_child);
     };
 
diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php
index d73513e..fd4052e 100644
--- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php
+++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php
@@ -87,8 +87,6 @@ public function testMatchRequestAllowed() {
 
   /**
    * Tests the matchRequest() function for access denied.
-   *
-   * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
    */
   public function testMatchRequestDenied() {
     $this->setupRouter();
@@ -98,6 +96,7 @@ public function testMatchRequestDenied() {
       ->method('checkRequest')
       ->with($request)
       ->willReturn($access_result);
+    $this->setExpectedException(AccessDeniedHttpException::class);
     $parameters = $this->router->matchRequest($request);
     $expected = [
       AccessAwareRouterInterface::ACCESS_RESULT => $access_result,
diff --git a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php
index c6d2843..4a9e0c6 100644
--- a/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php
+++ b/core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php
@@ -75,8 +75,6 @@ public function filterProvider() {
 
   /**
    * @covers ::filter
-   * @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException
-   * @expectedExceptionMessage No route found for the specified format xml.
    */
   public function testNoRouteFound() {
     $collection = new RouteCollection();
@@ -88,6 +86,7 @@ public function testNoRouteFound() {
     $request = Request::create('test?_format=xml', 'GET');
     $request->setRequestFormat('xml');
     $route_filter = new RequestFormatRouteFilter();
+    $this->setExpectedException(NotAcceptableHttpException::class, 'No route found for the specified format xml.');
     $route_filter->filter($collection, $request);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php
index 0cfbad5..ded951b 100644
--- a/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php
+++ b/core/tests/Drupal/Tests/Core/Routing/TrustedRedirectResponseTest.php
@@ -29,7 +29,6 @@ public function testSetTargetUrlWithInternalUrl() {
 
   /**
    * @covers ::setTargetUrl
-   * @expectedException \InvalidArgumentException
    */
   public function testSetTargetUrlWithUntrustedUrl() {
     $request_context = new RequestContext();
@@ -40,6 +39,7 @@ public function testSetTargetUrlWithUntrustedUrl() {
 
     $redirect_response = new TrustedRedirectResponse('/example');
 
+    $this->setExpectedException(\InvalidArgumentException::class);
     $redirect_response->setTargetUrl('http://evil-url.com/example');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php
index bdfb710..4d34b30 100644
--- a/core/tests/Drupal/Tests/Core/Site/SettingsTest.php
+++ b/core/tests/Drupal/Tests/Core/Site/SettingsTest.php
@@ -80,12 +80,11 @@ public function testGetHashSalt() {
    * @covers ::getHashSalt
    *
    * @dataProvider providerTestGetHashSaltEmpty
-   *
-   * @expectedException \RuntimeException
    */
   public function testGetHashSaltEmpty(array $config) {
     // Re-create settings with no 'hash_salt' key.
     $settings = new Settings($config);
+    $this->setExpectedException(\RuntimeException::class);
     $settings->getHashSalt();
   }
 
@@ -106,10 +105,9 @@ public function providerTestGetHashSaltEmpty() {
    * Ensures settings cannot be serialized.
    *
    * @covers ::__sleep
-   *
-   * @expectedException \LogicException
    */
   public function testSerialize() {
+    $this->setExpectedException(\LogicException::class);
     serialize(new Settings([]));
   }
 
diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php
index 3ed2b3d..974b374 100644
--- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php
+++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php
@@ -82,24 +82,20 @@ public function testToString() {
   }
 
   /**
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage $string ("foo") must be a string.
-   *
    * @covers ::__construct
    */
   public function testIsStringAssertion() {
     $translation = $this->getStringTranslationStub();
+    $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.');
     new TranslatableMarkup(new TranslatableMarkup('foo', [], [], $translation));
   }
 
   /**
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage $string ("foo") must be a string.
-   *
    * @covers ::__construct
    */
   public function testIsStringAssertionWithFormattableMarkup() {
     $translation = $this->getStringTranslationStub();
+    $this->setExpectedException(\InvalidArgumentException::class, '$string ("foo") must be a string.');
     $formattable_string = new FormattableMarkup('@bar', ['@bar' => 'foo']);
     new TranslatableMarkup($formattable_string);
   }
diff --git a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php
index 7a3dd3a..e599463 100644
--- a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php
+++ b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php
@@ -45,10 +45,10 @@ protected function setUp() {
    * Tests that dangerous methods cannot be called in entity objects.
    *
    * @dataProvider getTwigEntityDangerousMethods
-   * @expectedException \Twig_Sandbox_SecurityError
    */
   public function testEntityDangerousMethods($template) {
     $entity = $this->getMock('Drupal\Core\Entity\EntityInterface');
+    $this->setExpectedException(\Twig_Sandbox_SecurityError::class);
     $this->twig->render($template, ['entity' => $entity]);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php
index 5e3558e..08b8117 100644
--- a/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php
+++ b/core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php
@@ -95,10 +95,9 @@ protected function setUp() {
    * Ensures that passing an explicit group is not supported.
    *
    * @covers ::validate
-   *
-   * @expectedException \LogicException
    */
   public function testValidateWithGroups() {
+    $this->setExpectedException(\LogicException::class);
     $this->recursiveValidator->validate('test', NULL, 'test group');
   }
 
@@ -106,10 +105,9 @@ public function testValidateWithGroups() {
    * Ensures that passing a non typed data value is not supported.
    *
    * @covers ::validate
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testValidateWithoutTypedData() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->recursiveValidator->validate('test');
   }
 
@@ -228,8 +226,6 @@ protected function setupTypedData(array $tree, $name = '') {
 
   /**
    * @covers ::validateProperty
-   *
-   * @expectedException \LogicException
    */
   public function testValidatePropertyWithCustomGroup() {
     $tree = [
@@ -239,6 +235,7 @@ public function testValidatePropertyWithCustomGroup() {
       ],
     ];
     $typed_data = $this->setupTypedData($tree, 'test_name');
+    $this->setExpectedException(\LogicException::class);
     $this->recursiveValidator->validateProperty($typed_data, 'key1', 'test group');
   }
 
@@ -246,10 +243,9 @@ public function testValidatePropertyWithCustomGroup() {
    * @covers ::validateProperty
    *
    * @dataProvider providerTestValidatePropertyWithInvalidObjects
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testValidatePropertyWithInvalidObjects($object) {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->recursiveValidator->validateProperty($object, 'key1', NULL);
   }
 
@@ -289,10 +285,9 @@ public function testValidateProperty() {
    * @covers ::validatePropertyValue
    *
    * @dataProvider providerTestValidatePropertyWithInvalidObjects
-   *
-   * @expectedException \InvalidArgumentException
    */
   public function testValidatePropertyValueWithInvalidObjects($object) {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->recursiveValidator->validatePropertyValue($object, 'key1', [], NULL);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php
index ef6dd25..7afd0bb 100644
--- a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php
+++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php
@@ -102,9 +102,9 @@ public function providerFromUri() {
    *
    * @covers ::fromUri
    * @dataProvider providerFromInvalidUri
-   * @expectedException \InvalidArgumentException
    */
   public function testFromInvalidUri($uri) {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $url = Url::fromUri($uri);
   }
 
@@ -133,8 +133,6 @@ public function providerFromInvalidUri() {
    * Tests the createFromRequest method.
    *
    * @covers ::createFromRequest
-   *
-   * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
    */
   public function testCreateFromRequest() {
     $request = Request::create('/test-path');
@@ -144,6 +142,7 @@ public function testCreateFromRequest() {
       ->with($request)
       ->will($this->throwException(new ResourceNotFoundException()));
 
+    $this->setExpectedException(ResourceNotFoundException::class);
     $this->assertNull(Url::createFromRequest($request));
   }
 
@@ -179,12 +178,11 @@ public function testToString($uri) {
    * @depends testFromUri
    * @dataProvider providerFromUri
    *
-   * @expectedException \UnexpectedValueException
-   *
    * @covers ::getRouteName
    */
   public function testGetRouteName($uri) {
     $url = Url::fromUri($uri);
+    $this->setExpectedException(\UnexpectedValueException::class);
     $url->getRouteName();
   }
 
@@ -194,12 +192,11 @@ public function testGetRouteName($uri) {
    * @depends testFromUri
    * @dataProvider providerFromUri
    *
-   * @expectedException \UnexpectedValueException
-   *
    * @covers ::getRouteParameters
    */
   public function testGetRouteParameters($uri) {
     $url = Url::fromUri($uri);
+    $this->setExpectedException(\UnexpectedValueException::class);
     $url->getRouteParameters();
   }
 
@@ -210,11 +207,10 @@ public function testGetRouteParameters($uri) {
    * @dataProvider providerFromUri
    *
    * @covers ::getInternalPath
-   *
-   * @expectedException \Exception
    */
   public function testGetInternalPath($uri) {
     $url = Url::fromUri($uri);
+    $this->setExpectedException(\Exception::class);
     $this->assertNull($url->getInternalPath());
   }
 
diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php
index 64212b0..d60a58c 100644
--- a/core/tests/Drupal/Tests/Core/UrlTest.php
+++ b/core/tests/Drupal/Tests/Core/UrlTest.php
@@ -215,10 +215,10 @@ public function testFromUserInput($path) {
    * Tests the fromUserInput method with invalid paths.
    *
    * @covers ::fromUserInput
-   * @expectedException \InvalidArgumentException
    * @dataProvider providerFromInvalidInternalUri
    */
   public function testFromInvalidUserInput($path) {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $url = Url::fromUserInput($path);
   }
 
@@ -280,8 +280,6 @@ public function testCreateFromRequest() {
    * Tests that an invalid request will thrown an exception.
    *
    * @covers ::createFromRequest
-   *
-   * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
    */
   public function testUrlFromRequestInvalid() {
     $request = Request::create('/test-path');
@@ -291,6 +289,7 @@ public function testUrlFromRequestInvalid() {
       ->with($request)
       ->will($this->throwException(new ResourceNotFoundException()));
 
+    $this->setExpectedException(ResourceNotFoundException::class);
     $this->assertNull(Url::createFromRequest($request));
   }
 
@@ -315,11 +314,10 @@ public function testIsExternal($urls) {
    *
    * @depends testUrlFromRequest
    *
-   * @expectedException \UnexpectedValueException
-   *
    * @covers ::getUri
    */
   public function testGetUriForInternalUrl($urls) {
+    $this->setExpectedException(\UnexpectedValueException::class);
     foreach ($urls as $url) {
       $url->getUri();
     }
@@ -418,10 +416,10 @@ public function testGetRouteName($urls) {
    * Tests the getRouteName() with an external URL.
    *
    * @covers ::getRouteName
-   * @expectedException \UnexpectedValueException
    */
   public function testGetRouteNameWithExternalUrl() {
     $url = Url::fromUri('http://example.com');
+    $this->setExpectedException(\UnexpectedValueException::class);
     $url->getRouteName();
   }
 
@@ -445,10 +443,10 @@ public function testGetRouteParameters($urls) {
    * Tests the getRouteParameters() with an external URL.
    *
    * @covers ::getRouteParameters
-   * @expectedException \UnexpectedValueException
    */
   public function testGetRouteParametersWithExternalUrl() {
     $url = Url::fromUri('http://example.com');
+    $this->setExpectedException(\UnexpectedValueException::class);
     $url->getRouteParameters();
   }
 
@@ -630,7 +628,6 @@ public function testEntityUris($uri, $options, $route_name, $route_parameters, $
    * Tests the fromUri() method with an invalid entity: URI.
    *
    * @covers ::fromUri
-   * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
    */
   public function testInvalidEntityUriParameter() {
     // Make the mocked URL generator behave like the actual one.
@@ -639,6 +636,7 @@ public function testInvalidEntityUriParameter() {
       ->with('entity.test_entity.canonical', ['test_entity' => '1/blah'])
       ->willThrowException(new InvalidParameterException('Parameter "test_entity" for route "/test_entity/{test_entity}" must match "[^/]++" ("1/blah" given) to generate a corresponding URL..'));
 
+    $this->setExpectedException(InvalidParameterException::class);
     Url::fromUri('entity:test_entity/1/blah')->toString();
   }
 
@@ -753,10 +751,10 @@ public function providerFromValidInternalUri() {
    * Tests the fromUri() method with an invalid internal: URI.
    *
    * @covers ::fromUri
-   * @expectedException \InvalidArgumentException
    * @dataProvider providerFromInvalidInternalUri
    */
   public function testFromInvalidInternalUri($path) {
+    $this->setExpectedException(\InvalidArgumentException::class);
     Url::fromUri('internal:' . $path);
   }
 
@@ -825,10 +823,10 @@ public function providerTestToUriStringForRoute() {
   }
 
   /**
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage The route URI 'route:' is invalid.
+   * @covers ::fromUri
    */
   public function testFromRouteUriWithMissingRouteName() {
+    $this->setExpectedException(\InvalidArgumentException::class, "The route URI 'route:' is invalid.");
     Url::fromUri('route:');
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php
index b2d7700..01b16ad 100644
--- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php
+++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php
@@ -56,17 +56,17 @@ protected function setUp() {
 
   /**
    * @covers ::assemble
-   * @expectedException \InvalidArgumentException
    */
   public function testAssembleWithNeitherExternalNorDomainLocalUri() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->unroutedUrlAssembler->assemble('wrong-url');
   }
 
   /**
    * @covers ::assemble
-   * @expectedException \InvalidArgumentException
    */
   public function testAssembleWithLeadingSlash() {
+    $this->setExpectedException(\InvalidArgumentException::class);
     $this->unroutedUrlAssembler->assemble('/drupal.org');
   }
 
