diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 5e326138bace4001954990f1751138662bbca6d9..8db9e1811c1748bcb7d3509f98aded8ab8c9a681 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -2744,11 +2744,7 @@ protected function assertNoTitle($title, $message = '', $group = 'Other') {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertThemeOutput($callback, array $variables = array(), $expected, $message = '', $group = 'Other') {
-    $build = array('#theme' => $callback);
-    foreach($variables as $key => $variable) {
-      $build["#$key"] = $variable;
-    }
-    $output = drupal_render($build);
+    $output = theme($callback, $variables);
     $this->verbose('Variables:' . '<pre>' .  check_plain(var_export($variables, TRUE)) . '</pre>'
       . '<hr />' . 'Result:' . '<pre>' .  check_plain(var_export($output, TRUE)) . '</pre>'
       . '<hr />' . 'Expected:' . '<pre>' .  check_plain(var_export($expected, TRUE)) . '</pre>'
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
index a63355886ec9a564c7d99a029eaedeef188566fe..3cd898a4fb87f59a106393d51401fd94adacf80c 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php
@@ -46,15 +46,15 @@ function setUp() {
    *   - any attributes set in the template's preprocessing function
    */
   function testAttributeMerging() {
-    $output = theme('theme_test_render_element', array(
+    $theme_test_render_element = array(
       'elements' => array(
         '#attributes' => array('data-foo' => 'bar'),
       ),
       'attributes' => array(
         'id' => 'bazinga',
       ),
-    ));
-    $this->assertIdentical($output, '<div id="bazinga" data-foo="bar" data-variables-are-preprocessed></div>' . "\n");
+    );
+    $this->assertThemeOutput('theme_test_render_element', $theme_test_render_element, '<div id="bazinga" data-foo="bar" data-variables-are-preprocessed></div>' . "\n");
   }
 
   /**
@@ -222,7 +222,7 @@ function testThemeGetSetting() {
    * Ensures the theme registry is rebuilt when modules are disabled/enabled.
    */
   function testRegistryRebuild() {
-    $this->assertIdentical(theme('theme_test_foo', array('foo' => 'a')), 'a', 'The theme registry contains theme_test_foo.');
+    $this->assertThemeOutput('theme_test_foo', array('foo' => 'a'), 'a', 'The theme registry contains theme_test_foo.');
 
     module_disable(array('theme_test'), FALSE);
     // After enabling/disabling a module during a test, we need to rebuild the
@@ -230,7 +230,7 @@ function testRegistryRebuild() {
     // throws an exception.
     $this->rebuildContainer();
     $this->container->get('module_handler')->loadAll();
-    $this->assertIdentical(theme('theme_test_foo', array('foo' => 'b')), FALSE, 'The theme registry does not contain theme_test_foo, because the module is disabled.');
+    $this->assertThemeOutput('theme_test_foo', array('foo' => 'b'), FALSE, 'The theme registry does not contain theme_test_foo, because the module is disabled.');
 
     module_enable(array('theme_test'), FALSE);
     // After enabling/disabling a module during a test, we need to rebuild the
@@ -238,7 +238,7 @@ function testRegistryRebuild() {
     // throws an exception.
     $this->rebuildContainer();
     $this->container->get('module_handler')->loadAll();
-    $this->assertIdentical(theme('theme_test_foo', array('foo' => 'c')), 'c', 'The theme registry contains theme_test_foo again after re-enabling the module.');
+    $this->assertThemeOutput('theme_test_foo', array('foo' => 'c'), 'c', 'The theme registry contains theme_test_foo again after re-enabling the module.');
   }
 
   /**
@@ -251,7 +251,7 @@ function testDrupalRenderChildren() {
         '#markup' => 'Foo',
       ),
     );
-    $this->assertIdentical(theme('theme_test_render_element_children', $element), 'Foo', 'drupal_render() avoids #theme recursion loop when rendering a render element.');
+    $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', 'drupal_render() avoids #theme recursion loop when rendering a render element.');
 
     $element = array(
       '#theme_wrappers' => array('theme_test_render_element_children'),
@@ -259,7 +259,7 @@ function testDrupalRenderChildren() {
         '#markup' => 'Foo',
       ),
     );
-    $this->assertIdentical(theme('theme_test_render_element_children', $element), 'Foo', 'drupal_render() avoids #theme_wrappers recursion loop when rendering a render element.');
+    $this->assertThemeOutput('theme_test_render_element_children', $element, 'Foo', 'drupal_render() avoids #theme_wrappers recursion loop when rendering a render element.');
   }
 
   /**