我有一个Zend-Framework2项目,我有问题来组织我的单元测试。我的单元测试位于每个模块的一个“测试”-folder中。如果我在模块的测试文件夹中使用phpunit从命令行运行测试,则测试将成功运行。
示例:
c:\project\module\AccessControl\test>phpunit
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from c:\project\module\AccessControl\test\phpunit.xml
........Time: 0 seconds, Memory: 8.25Mb
OK (8 tests, 10 assertions)Problem:这里只有一个模块将被测试。但是我想从c:\ project \文件夹中运行一个测试套件来测试这个洞项目。我在这里放了一个bootstrap.php和一个phpunit.xml。
从我使用的命令行运行它:
C:\project\tests>phpunit --调试--配置phpunit.xml
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from C:\project\tests\phpunit.xml
Starting test 'AccessControlTest\Model\AuthenticationTest::testInitDefault'.
PHP Fatal error: Class 'AccessControlTest\Bootstrap' not found in C:\project\module\AccessControl\test\AccessControlTest\Model\AuthenticationTest.php on line 22
PHP Stack trace:
PHP 1. {main}() C:\Program Files (x86)\PHP\phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() C:\Program Files (x86)\PHP\phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\TextUI\Command.php:129
PHP 4. PHPUnit_TextUI_TestRunner->doRun() C:\Program Files (x86)\PHP\PEAR\PHPUnit\TextUI\Command.php:176
PHP 5. PHPUnit_Framework_TestSuite->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\TextUI\TestRunner.php:346
PHP 6. PHPUnit_Framework_TestSuite->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestSuite.php:705
PHP 7. PHPUnit_Framework_TestSuite->runTest() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestSuite.php:745
PHP 8. PHPUnit_Framework_TestCase->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestSuite.php:775
PHP 9. PHPUnit_Framework_TestResult->run() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestCase.php:769
PHP 10. PHPUnit_Framework_TestCase->runBare() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestResult.php:648
PHP 11. AccessControlTest\Model\AuthenticationTest->setUp() C:\Program Files (x86)\PHP\PEAR\PHPUnit\Framework\TestCase.php:821phpunit.xml文件如下所示:
<phpunit bootstrap="./Bootstrap.php" colors="true" verbose="true">
<testsuite name="SgtrCatalogTestsuite">
<directory>../module/AccessControl</directory>
</testsuite>
</phpunit>看上去有些模块路径不正确。有人能帮忙告诉我怎么设置这个吗?
编辑 Ty为您的答复!
与此同时,我发现了这个:How to consolidate ZF2 unit/application module tests into a single call?
似乎不可能从根级运行所有模块测试。我现在试着使用它,并让您知道它是否有效:https://github.com/prolic/HumusPHPUnitModule
发布于 2014-11-05 15:28:43
尝试在您的composer.json中添加此部分
"autoload": {
"psr-0": {
"AccessControlTest\\": "tests/",
"AccessControl\\": "src/module/AccessControl/src/"
}
}然后跑
$ php composer.phar dump-autoloadhttps://stackoverflow.com/questions/26712290
复制相似问题