Does class autoloading not work in standalone phpunit testing?
This is an issue with intermediate base-classes for tests (like VolunteerTestAbstract). The most reliable solution I've found is to put a require_once to load the intermediate base-class. For example, this is what I used in uk.co.vedaconsulting.mosaico:

require_once __DIR__ . '/TestCase.php';

class CRM_Mosaico_MosaicoTemplateTest extends CRM_Mosaico_TestCase implements EndToEndInterface {
     ...
}


Unfortunately, it's hard to combine PHPUnit with a classloader that understands extensions. To see why, consider an example command:

phpunit4 tests/phpunit/CRM/Mosaico/MosaicoTemplateTest.php


Which would then:


A. Load test files, e.g.


Load tests/phpunit/bootstrap.php
Load tests/phpunit/CRM/Mosaico/MosaicoTemplateTest.php (which depends on a base class like CRM_Mosaico_TestCase)
Load tests/phpunit/CRM/Mosaico/TestCase.php

B. Begin executing the test logic, e.g.


Execute CiviTestListener
Execute setupBeforeClass()
Execute setUp()



The problem arises if the database-initialization (eg \Civi\Test::headless()-&gt;installMe(__DIR__)-&gt;apply()) is put in phase B test-logic (e.g. CiviTestListener or setupBeforeClass() or setUp()) . The database-initialization determines which extensions are active. The active extensions determine the class-loader. But all of this comes too late. During steps A2=>A3 (when we need autoloading), the extension-enabled class-loader isn't available yet.

Put another way: any code which references an autoloaded extension class has an implicit dependency on the database.

One can resolve this conundrum a couple ways, e.g.


In tests/phpunit/bootstrap.php, fully initialize the system. (Ex: In the line eval(cv('php:boot --level=classloader', 'phpcode'));, change the --level to settings or full.) This makes sense if all the tests are end-to-end (e2e).
Load classes in a way which does not implicitly depend on the database. The simplest thing is to do a require_once to load the target class. (EDIT: What's a nice place to put the require_once statement? I originally put it in each test class, but on second thought... it would be more elegant to put it in tests/phpunit/boostrap.php.)


(I'm writing this to help me get the problem a bit clearer in mind... hopefully that will eventually lead to a better solution...)