API Extension PHPUnit Tests not working
Agree with JohnFF and JonG that it's good to look at buildkit/civibuild for this. If you review the main page for the test suite (http://wiki.civicrm.org/confluence/display/CRMDOC/Testing), you'll notice a common theme -- all the tests should work out of the box on new builds if you use civibuild. (They need to -- because the civicrm.org test infrastructure runs on civibuild.) A manual installation requires more work.

In this case, the instructions you've come across in Setting up your personal testing sandbox HOWTO are out-of-date -- those instructions apply from roughly v2.x - v4.6. The test-runner changed a bit in v4.7.

How it works in v4.6 and earlier: Civi included a fork of phpunit with several small patches, and the tests only worked if you used this fork of PHPUnit. This had several consequences like:


Every developers' copy of CiviCRM required an extra config file under test/phpunit/CiviTest.
Upgrading phpunit (eg to run in newer versions of PHP) was onerous.
Running a test-class in an extension was pretty hard. You needed a way to link your test with the Civi installation. (The location varies depending on the CMS and configuration.)
Running a test in an IDE was... hard? impossible? (I never did it 4.6 or earlier.)


How it works in v4.7: Tests are no longer special programs with a strongly-prescribed structure. Instead, we've addressed the broader problem of how to load Civi in your CLI scripts. You can use any test-runner (phpunit, codeception, behat, etc) with any package (civicrm-core, civicrm-drupal, or an extension). A "Civi enabled test" is just a plain-old PHP script which includes a line like this:

eval(`cv php:boot`); // or...
eval(`cv php:boot --test`); // or...
eval(`cv php:boot --level=classloader`);


The cv tool is responsible for loading/booting CiviCRM in your test.

When designing tests, there are different types of tests... such as bare unit-tests, headless database tests, and end-to-end tests. For more discussion about these concepts, see:


https://github.com/civicrm/org.civicrm.testapalooza
https://civicrm.org/blog/totten/developers-extension-testapalooza


If you haven't used civibuild, then pay particular attention to the README for org.civicrm.testapalaooza under "Setup: Option B: Manual".