5

In Drupal 8, I am creating functional tests extending the BrowserTestBase class.

Launching a test though (even an empty one) requires about 2-3 minutes.

Is this normal, is it there a way to speed up the functional tests?

6
  • For a single test, that seems a bit long. For a test group, that could be fast! Are you executing in the UI or the command-line runner? – cilefen Aug 31 '16 at 13:37
  • Command-line runner, initially I thought it was my test, so I created an empty one and got these results. Is there a way to know where the time is spent? – David Riccitelli Aug 31 '16 at 14:16
  • If you save the database tables from the test, it's watchdog log may help. Also, profiling with Blackfire, Xdebug, or xhprof will show you the slow functions. – cilefen Aug 31 '16 at 15:04
  • What is your value of the PHP configuration opcache.enable_cli? – cilefen Aug 31 '16 at 15:12
  • It's Off: $ php -i | grep enable_cli returns opcache.enable_cli => Off => Off – David Riccitelli Aug 31 '16 at 15:17
4

Do not use standard (as you said in a comment).

Use testing and then create only what you need in the test. That's the main thing to speed up your tests.

They are still rather slow, but that should help.

Another thing to consider is to avoid having many test methods. Each runs in a completely new, isolated environment. A trick that is often used is to have a single testAll() method and many doTestSomething() methods, then they are faster by almost factor count(test methods), since set up is usually by far the slowest part.

You can also run tests in parallel with --concurrency 8 (nummber of cpus is a pretty good value for concurrency)

2
  • how do I set the 'taxonomy.vocabulary.tags' required when using the 'testing' profile? – David Riccitelli Sep 26 '16 at 9:30
  • I decoupled some modules and now I am testing with the 'testing' profile and a minimal requirement of dependencies and I got down from 3 minutes to around 20-30 seconds. Thanks! – David Riccitelli Sep 26 '16 at 12:10
2

Which one are you using? Do note that there are two BrowserTestBase classes, one is marked as deprecated:

https://api.drupal.org/api/drupal/core%21tests%21Drupal%21Tests%21BrowserTestBase.php/class/BrowserTestBase/8.2.x

Here is what I wrote for Taxonomy Views Integrator:

http://cgit.drupalcode.org/tvi/tree/tests/src/Functional

I can run that test and (if I recall) it is done in less than 60 seconds. Note that the more test methods you define, more modules you require, the longer it will take to set up the testing instance of Drupal.

On a VM I have dedicated 2GB of RAM, 256M for PHP 5.6 (or 7, depending on which VM) on DrupalVM.com instance.

Also, I am running them from the command line, not the UI test runner.

2
  • Hello @kevin, I am using the same class Drupal\Tests\BrowserTestBase on a MacBook Air 8GB of memory, PHP 5.6, using the command line. For my functional tests I need to use the standard profile (I am using taxonomies), I enable the node and taxonomy modules and 2 custom modules. – David Riccitelli Aug 31 '16 at 14:14
  • Okay, I am using the default (testing), but I would gather that it would cause a test to take longer to spin up instead of start with only what you need if you use a full site install like standard. What happens if you don't set a profile? Does that reduce the time? – Kevin Aug 31 '16 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.