How to run PHPUnit tests? Drupal 8 is supplementing the testing framework based on Simpletest with PHPUnit, and Simpletest could be removed in Drupal 9.

I'm not upgrading yet to Drupal 8, but I was wondering how I can write existing tests in PHPUnit (to follow-up with the trend) for Drupal 7, instead in Simpletest?

Is there any method or module for integrating PHPUnit with Drupal 7?

There are few like phpunit or drunit, but they're not for Drupal 7.
You can get PHPUnit tests to run by bootstrapping Drupal within each of your test files. It's not ideal, but it does work.


define('DRUPAL_ROOT', 'your/path/to/drupal');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

// Bootstrap Drupal.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// Proceed with PHPUnit tests as usual from here.
class MyTest extends \PHPUnit_Framework_TestCase {
  ...