How to stop PHPUnit from adding included/required files as part of the testsuite?
I tried to follow the PHPUnit manual on how to setup a testsuite with a custom test execution order. I now realized that i only need these lines and some includes to get the suite working:
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Package');
return $suite;
}
But when i use the above lines the test execution order is defined by the sort order of my includes. And when i try to change it via suite() as followes the tests are executed twice, first in the sort order as defined by suite() and after that in the sort order of the includes:
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Package');
$suite->addTestSuite('Package_Class1Test');
$suite->addTestSuite('Package_Class2Test');
$suite->addTestSuite('Package_Class3Test');
return $suite;
}
Includes are done by:
require_once 'Package/Class3Test.php';
require_once 'Package/Class2Test.php';
require_once 'P开发者_Python百科ackage/Class1Test.php';
Result (test execution order):
1) Class1Test
2) Class2Test
3) Class3Test
4) Class3Test
5) Class2Test
6) Class1Test
I am using Netbeans 7.0beta to run the PHP 5.3.5 / PHPUnit 3.5.11 on windows 7. I read the phpunit manual (http://www.phpunit.de/manual/3.5/en/organizing-tests.html) but i have no clue what i am doing wrong...
Please help.
PS: This problem can be solved by autoloading the classes.
PHPUnit 3.5 was released five years ago and has not been supported for four years. But even five years ago using PHPUnit_Framework_TestSuite
objects to compose a test suite was no longer considered a good practice.
Please read the Getting Started article on the PHPUnit website as well as the chapter on organizing tests in the PHPUnit manual to learn how to properly organize your test suite.
Are you calling phpunit
with the right parameters?
I have this setup, which works fine with suites.
/tests/
/tests/allTests.php
/tests/lib/
/tests/lib/libAllTests.php
/tests/lib/baseTest.php
/tests/lib/coreTest.php
/tests/lib/...
allTests.php:
require_once 'lib/libAllTests.php';
class AllTests
{
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Project');
$suite->addTestSuite('LibAllTests');
return $suite;
}
}
libAllTests.php:
require_once 'baseTest.php';
require_once 'coreTest.php';
class LibAllTests
{
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Lib');
$suite->addTestSuite('CoreTest');
$suite->addTestSuite('BaseTest');
return $suite;
}
}
From a command prompt I can call:
phpunit /tests/allTests.php
: Runs all testsphpunit /tests/lib/libAllTests.php
: Runs all lib testsphpunit /tests/lib/baseTest.php
: Runs all base testsphpunit /tests/*
: Runs all tests
And in all four scenarios, the core tests are run before base tests, and no tests are repeated twice.
I'm using phpUnit 3.5.7.
精彩评论