2

It makes sense to run each test in a completely clean environment. However, before tests can be run, they have to be developed, during this process it is so frustrating to have to wait 3 or 4 minutes each time to see the result of any change/correction in the test.

Is there any trick to somehow resume the test in the environment where is finished or broke last time, without recreating the whole Drupal database? At this point, I am not interested in the tests to be 100% reliable, but rather in getting rid of more or less obvious errors in tests themselves.

For example, in my WebTestCase, I wrote $myfunction instead of $myfunction() and the test failed. The test so far created a content type, so in order to re-run it in the same environment, I would just delete that content type if exists, etc. It would be quicker.

1

No, there isn't. Simpletest doesn't know if your last test run was successful, or maybe broke something within the test environment, or if you changed it. That alone would be problematic, beside technical reasons. Also, the really slow part isn't your custom setUp() code but setting up a complete Drupal installation every time.

There are some tricks to improve the speed, however.

  • Use the testing profile by adding a protected $profile = 'testing'; to your test class. Maybe you need to define a few additional dependencies though, because that only installs the absolutely required modules. This improves test speed ~50%.
  • Have a single public test*() method, which calls a number of functions. Then you only need a single set-up for the whole test class. However, you need to be aware that your test methods aren't run in a separate environment anymore.
  • "Hacking" core by changing the default engine from InnoDB to MyISAM. That makes create TABLE statements much faster.
  • Improve your MySQL configuration, here's my configuration as an example: http://techblog.md-systems.ch/blog/improve-mysql-performance
  • When actively working on a single test method and the class has multiple ones, disable the others by replacing function test... with function dtest... Don't forget to revert that before committing.

A single test method takes ~10 seconds on my laptop. That's not too bad.

  • Thanks for the tips!! Combining all those together, I now have the tests running for 35 seconds and this is wonderful. – camcam May 15 '12 at 0:31
0

I realize that this is an old, long-since-answered question, but anyone else who finds this via google (like I just did), will probably appreciate this.

There's a contrib module called SimpleTest Clone, which supplies a replacement for the the DrupalWebTestCase class, called SimpleTestCloneTestCase. If you derive your test class from this new class, it will clone the active database for each test (instead of rebuilding your site from scratch). On a small testing site, this takes maybe 10-15 seconds: far faster than the complete rebuild process.

It's also useful if you need to run your tests against live site data.

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.