Problem/Motivation

There are still functional tests that can be converted, entirely or partially into Kernel/Unit tests.

Functional tests (aka Browser tests) install a complete Drupal site, using a virtual browser. This makes them slow to run.

In many cases, the same functionality could be tested in a kernel test. These are much quicker to run.

Quicker tests mean:

- better DX when developers run tests manually
- lower carbon footprint for drupal.org and any other organisations running Drupal's tests
- cheaper running costs for Drupal's CI
- quicker results for developers' merge requests and patches

Proposed resolution

Identify them and convert them:

Discovered so far:

Done:

Won't fix:

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

CommentFileSizeAuthor
#85 3041700-strict-btb-tests.patch6.85 KBlongwave

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

I use this script to discover such tests:

<?php

/** @var \Drupal\Core\Extension\ModuleExtensionList $ml */
$ml = \Drupal::service('extension.list.module');
/** @var \Drupal\Core\Extension\ThemeExtensionList $tl */
$tl = \Drupal::service('extension.list.theme');

$paths = ['core/tests/Drupal/FunctionalTests'];
foreach ([$ml, $tl] as $service) {
  foreach ($service->getList() as $extension) {
    $path = $extension->getPath() . '/tests/src/Functional';
    if (is_dir($path)) {
      $paths[] = $path;
    }
  }
}

foreach ($paths as $path) {
  $test_files = file_scan_directory($path, '/.*Test\.php$/');
  foreach ($test_files as $file_path => $test_file) {
    $content = file_get_contents($file_path);
    if (!preg_match('/drupal(Get|Login|PostForm)\(/', $content)) {
      print "$file_path\n";
    }
  }
}

The script should run with drush scr.

It detects a lot of tests that are not to be converted. But still helps. To be improved.

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

amateescu’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

mile23’s picture

mile23’s picture

feuerwagen’s picture

Issue summary: View changes

Moved fixed issues to separate list.

claudiu.cristea’s picture

Issue summary: View changes

Moved fixed issues to Done.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

mile23’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

mile23’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

phenaproxima’s picture

Issue summary: View changes

Updating the IS to reflect some recent commits. :)

naveenvalecha’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

Title: [META] Convert some tests into Kernel tests » [META] Convert some tests into Kernel or Unit tests
Issue summary: View changes
claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

naveenvalecha’s picture

Issue summary: View changes

Updated IS

feuerwagen’s picture

Issue summary: View changes

More issues are done.

claudiu.cristea’s picture

Issue summary: View changes

More issues are fixed.

feuerwagen’s picture

Issue summary: View changes

Getting there

manuel garcia’s picture

Issue summary: View changes

Was about to open a new one for DrupalDateTimeTest but it ends up there's already an issue for it, so adding it to the list here: #2349453: Move \Drupal\Tests\system\Functional\Datetime\DrupalDateTimeTest::testTimezoneFormat into a Kernel test

krzysztof domański’s picture

Issue summary: View changes

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

joachim’s picture

I think there's a lot of functional tests that make browser requests as part of setting up content types, fields and so on. Those could be converted to API calls.

I've added #3211229: Add an API-based equivalent to FieldUiTestTrait with similar methods as a child issue; I'll try to find time to create issues for tests where this can be converted.

longwave’s picture

While looking at #3048423: Convert RelationshipUserFileDataTest into a Kernel test I wondered if we can mark BTB tests as "risky" or similar if e.g. they do not perform a drupalGet(). This won't catch everything that strictly doesn't need it but that one and #2349453: Move \Drupal\Tests\system\Functional\Datetime\DrupalDateTimeTest::testTimezoneFormat into a Kernel test for starters would be picked up.

longwave’s picture

StatusFileSize
new6.85 KB

A test patch for #84, this causes functional tests that do not perform HTTP requests to fail.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

joachim’s picture

Added issue summary from a duplicate I accidentally created today, & related issue for doing setup with API calls.

joachim’s picture

Issue summary: View changes
joachim’s picture

Issue tags: +sustainability

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mglaman’s picture

I have stopped writing Functional tests and always use Kernel tests.

Here’s a bunch of examples I’ve done: https://git.drupalcode.org/project/google_tag/-/tree/2.0.x/tests/src/Ker...

It handles requests by passing it to the HTTP kernel. The above even tests user register and login.

That code is based on a personal library I use: https://github.com/mglaman/drupal-test-helpers

joachim’s picture

Issue summary: View changes
joachim’s picture

Issue summary: View changes

Found a few more.

Sniff: calling $container->set() in a browser test is a dead giveaway -- it will have no effect on the SUT since that is getting the service container from cache or building it from YAML files!

catch’s picture

catch’s picture

Issue summary: View changes
catch’s picture

FormElementsLabelTest is a potential candidate here - at least the last method does not http requests.

quietone’s picture

Issue summary: View changes

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.