Error running a PHPUnit test only under run-tests.sh I'm working on an 8.x module that uses PHPUnit tests.  I've been running these from the command line using the embedded phpunit script that's installed with Drupal 8:

../vendor/bin/phpunit PATH/TO/MY/FILE.php


Both of my tests work w/o any problems under both PHP 5.5 and PHP 5.6.

But the Drupal testbot is failing both of my tests with the error

Fatal error: Trait 'Drupal\Tests\my_module\MockSessionTrait' not found in /var/www/.../PATH/TO/MY/FILETest.php


Using phpunit from the command line, this same trait is found w/o any trouble.

If I run the tests myself from the command line, but this time using run-tests.sh, I get the same error the testbot gets:

php scripts/run-tests.sh --url http://192.168.88.42/drupal --class 'Drupal\Tests\my_module\Unit\FILETest'


The stack trace looks like this:

PHP Stack trace:
PHP   1. {main}() /var/www/drupal/core/scripts/run-tests.sh:0
PHP   2. simpletest_script_get_test_list() /var/www/drupal/core/scripts/run-tests.sh:76
PHP   3. class_exists() /var/www/drupal/core/scripts/run-tests.sh:807
PHP   4. spl_autoload_call() /var/www/drupal/core/scripts/run-tests.sh:807
PHP   5. Symfony\Component\ClassLoader\ApcClassLoader-&gt;loadClass() /var/www/drupal/core/scripts/run-tests.sh:0
PHP   6. require() /var/www/drupal/vendor/symfony/class-loader/ApcClassLoader.php:114


I'm guessing that I need to help run-tests.sh to find my files, somehow.

Any advice from anyone as to why run-tests.sh behaves differently here from stock phpunit?
@Berdir is completely correct here:


  I'm not sure but you might not be able to have a non-test class in the tests/src location, try moving that to module/src/... and change the namespace accordingly (Drupal\module...


While PHPUnit doesn't mind if a test class uses a trait that's in a Drupal\Tests namespace, the simpletest test runner run-tests.sh will be unable to find the trait if you do this.

So don't do that.

Even if a trait is used only with your test classes, if you want your code to get past the Drupal testbot, the trait needs to live somewhere in your Drupal\your_module\ namespace. Do this, and both phpunit and run-tests.sh will be happy.