diff --git a/core/tests/Drupal/Tests/Phpunit5FCTrait.php b/core/tests/Drupal/Tests/Phpunit5FCTrait.php
new file mode 100644
index 0000000000..1443f021fb
--- /dev/null
+++ b/core/tests/Drupal/Tests/Phpunit5FCTrait.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Drupal\Tests;
+
+use PHPUnit\Framework\TestCase;
+use PHPUnit_Framework_MockObject_MockObject;
+
+/**
+ * This trait makes tests forward compatible with PHPUnit 5 and above.
+ */
+trait Phpunit5FCTrait {
+
+  /**
+   * Returns a mock object for the specified class using the available method.
+   *
+   * The getMock method is deprecated in PHPUnit 5 but the createMock method is
+   * not available in PHPUnit 4. To provide forward compatibility this trait
+   * provides the getMock method and uses createMock if this method is
+   * available on the parent class.
+   *
+   * @param string $originalClassName
+   *   Name of the class to mock.
+   * @param array|null $methods
+   *   When provided, only methods whose names are in the array are replaced
+   *   with a configurable test double. The behavior of the other methods is not
+   *   changed. Providing null means that no methods will be replaced.
+   * @param array $arguments
+   *   Parameters to pass to the original class' constructor.
+   * @param string $mockClassName
+   *   Class name for the generated test double class.
+   * @param bool $callOriginalConstructor
+   *   Can be used to disable the call to the original class' constructor.
+   * @param bool $callOriginalClone
+   *   Can be used to disable the call to the original class' clone constructor.
+   * @param bool $callAutoload
+   *   Can be used to disable __autoload() during the generation of the test
+   *   double class.
+   * @param bool $cloneArguments
+   * @param bool $callOriginalMethods
+   * @param object $proxyTarget
+   *
+   * @see \PHPUnit_Framework_TestCase::getMock
+   *
+   * @return PHPUnit_Framework_MockObject_MockObject
+   */
+  public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null) {
+    if (method_exists('PHPUnit\Framework\TestCase', 'createMock')) {
+      return TestCase::createMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
+    }
+    return parent::getMock($originalClassName, $methods, $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php
index 8aaeb85743..972b544dee 100644
--- a/core/tests/Drupal/Tests/UnitTestCase.php
+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -18,6 +18,8 @@
  */
 abstract class UnitTestCase extends TestCase {
 
+  use Phpunit5FCTrait;
+
   /**
    * The random generator.
    *
