<...">

Why is PHPUnit trying to find a file called testuite?

I have this in my phpunit.xml file:

<phpunit ...> <testsuites> <testsuite name="MyTests"> <directory>../path/to/some/tests</directory> </testsuite> </testsuites> ... // more settings for <filter> and <logging> </phpunit> 

And when I go to run it, I get this error:

 PHP fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "MyTests.php" nor "MyTests.php" could be opened.' 

Why is PHPUnit giving me this error and why is it looking for "MyTests.php" if I gave it a directory to search for tests?

And in a related note, when I add more <testsuite> entries with other tests, PHPUnit works without errors. What's up with that?

+7
source share
2 answers

By default, PHPUnit will add "all *Test classes that are in the *Test.php files" (see PHPUnit docs ). If he does not find files matching this description (for example, the SomeTest.php file defining the SomeTest class), he returns to search for the file based on the attribute name of the test set.

The solution is to create a file that matches this description so that PHPUnit does not return to its search standard called testuite:

 <?php // in ../path/to/some/tests/SomeTest.php: class SomeTest extends PHPUnit_Framework_TestCase { public function test() { //... test cases here } } ?> 

Now you can run phpunit without errors:

 $ phpunit PHPUnit 3.5.14 by Sebastian Bergmann. . Time: 0 seconds, Memory: 10.75Mb OK (1 test, 0 assertions) 

It will work without errors if you add more testsuite entries, if PHPUnit can find the appropriate test cases to run in these other sets. If he finds tests to run in any testuite test, he will not resort to searching with the name attribute for collections for which he cannot find anything.

+5
source

I believe the problem is that you are not saying which files contain test cases and / or suites that you want to run. Try adding the suffix="Test.php" attribute.

 <testsuite name="MyTests"> <directory suffix="Test.php">../path/to/some/tests</directory> </testsuite> 
+1
source

All Articles