Integration Testing Framework for Drupal

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by neeravbm on February 24, 2015 at 5:45pm

We have created an integration testing framework for Drupal based on PHPUnit. It simplifies creating and maintaining integration tests for Drupal. It understands Drupal so a lot of tedious tasks are done by it in the background and the developer can concentrate on just testing business logic.

Here is an example of an integration test where we are creating a sample News node as an admin user without filling two required fields but filling everything else. The framework will fill all the field values for you in the background, including taxonomy terms and entity references so that the developer can concentrate on just testing the business logic (required fields in this case).

// Log in as an admin user
$userObject = User::loginProgrammatically('admin');

// Fill News node form without Family and Displayed fields, both of which are required
$newsForm = new NewsForm();
$skip = array('field_family', 'field_displayed',);
list($output, $fields, $msg) = $newsForm->fillDefaultValues($skip);
$this->assertTrue($output, $msg);

$output = $newsForm->submit();
$this->assertFalse($output, "Administrator was able to create a News node even though required fields Family and Displayed are empty.");

$userObject->logout();

This is a very basic example but hopefully you get the idea. Do you guys think that such a framework will be useful to the community? If yes, we'll enhance it a little bit and contribute it back to the community. On the other hand, if you have any feedback on what you would like to see in such a framework and how we can improve it, please share that as well.

Comments

Hi! It looks interesting

Posted by omissis on February 24, 2015 at 7:15pm

Hi! It looks interesting indeed, how did you implement it?
Maybe you could find interesting to take a look at phpunit-mink and at the way the Drupal Behat Extension does the same thing?
It might be interesting to evaluate if it's possible to extract that part into a Drupal Mink Extension that then could be reused from both phpunit and behat (and phpspec?).
Just wondering :)

Here's a couple of links:
* https://github.com/minkphp/phpunit-mink
* https://github.com/jhedstrom/drupalextension/blob/master/src/Drupal/Drup...

This looks very similar to

Posted by jhedstrom on February 24, 2015 at 10:37pm

This looks very similar to the intent of the Drupal Driver, which has been extracted from the aforementioned Drupal Behat Extension so that it can be used for non-Behat projects (eg, with PHPUnit, Codeception, etc).

ah! I did use the Drupal

Posted by omissis on February 24, 2015 at 11:20pm

ah! I did use the Drupal Behat Extension but I have never noticed the Drupal Driver, looks awesome! :)

Interesting!

Posted by neeravbm on February 24, 2015 at 11:57pm

Awesome! I didn't know about the Drupal Driver. It looks pretty interesting and we should be able to use it for our automated testing efforts. Why do you think it's not being used much? Is it because generally Drupal projects are pretty small or Drupal developers don't like automated testing? :)

The Drupal Driver as a

Posted by jhedstrom on February 25, 2015 at 3:51am

The Drupal Driver as a separate project has only existed since the Behat Drupal Extension released version 3 in November, so the number of installs there mainly reflect adoption rates of the newest version. The older version was part of the Behat Drupal Extension 1, which has many more installs.

Hi Thanks for Sharing

Posted by tburke on February 25, 2015 at 3:50pm

The Framework looks interesting and has a lot of potential.

Also, Thanks for sharing the Drupal Driver for Behat. I'll have to take a look at that.

Difference from SimpleTest?

Posted by kentr on April 7, 2015 at 2:53pm

I'm under the (perhaps mistaken) impression that PHPUnit and SimpleTest are very similar.

Does this integration provide features that the SimpleTest integration doesn't (besides the obvious that it's for PHPUnit instead)?

Speedup and TDD

Posted by neeravbm on May 25, 2015 at 2:12am

Yes, it's about 60 times faster to run than Simpletest. This has also enabled us to do TDD. A lot of time is being saved because the framework bootstraps Drupal only once.

Open-source

Posted by neeravbm on June 11, 2015 at 9:38pm

We have finally managed to make the integration testing framework open-source. Check it out here: http://redcrackle.com/red-test/documentation/first-integration-test. Let me know your feedback. I will probably write a bigger post on d.o. once I have some time.

Testing and Quality Assurance

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /