我想用Grunt自动化CakePHP测试,并找到了grunt.loadNpmTasks('grunt-phpunit');
,它可以自动化PHPUnit,但我确信它不能处理cake test
。
我也对Grunt中运行cake test
的解决方案感到满意,但我对运行PHPUnit命令的方法非常感兴趣,该命令可以执行CakePHP测试。
编辑:我使用的是CakePHP的当前稳定版本,现在是2.5.4。
我假设grunt phpunit需要默认的标准phpunit执行,如果是这样的话,你就不能用这种方式运行它,你必须熟练使用这个工具。我猜它正在解析测试输出。CakePHP2不允许像现在使用CakePHP和其他库那样简单地运行"phpunit"。CakePHP2扩展了phpunit测试类,所以我怀疑您是否可以在不使用cakephp测试shell的情况下运行它们。
我们使用Jenkins和我们自己定制的脚本来自动化测试。
我找到了一个解决方案。
在一个日本网站上,我发现了一个有趣的想法:
首先,我必须将webroot/test.php
复制为webroot/phpunit.php
,并替换最后一行:
--- a/webroot/test.php
+++ b/webroot/phpunit-bootstrap.php
@@ -86,4 +86,4 @@ if (Configure::read('debug') < 1) {
require_once CAKE . 'TestSuite' . DS . 'CakeTestSuiteDispatcher.php';
-CakeTestSuiteDispatcher::run();
+App::load('CakeTestSuiteCommand');
这使得将其用作PHPUnit的引导程序成为可能。
然后您可以创建一个phpunit.xml
来简化测试过程。
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" stopOnFailure="false" bootstrap="webroot/phpunit-bootstrap.php">
<testsuites>
<testsuite name="AllTests">
<directory suffix=".php">Test/Case</directory>
</testsuite>
</testsuites>
</phpunit>
现在我只需要将grunt-phpunit
配置添加到我的Gruntfile.js
:
phpunit: {
options: {
bin: 'phpunit',
configuration: 'phpunit.xml',
colors: true,
},
app: {
options: {
testsuite: 'AllTests',
},
},
}
现在,如果我运行grunt phpunit
(或配置grunt watch
在更改时运行phpunit
任务,并更改文件),PHPUnit将运行我的测试。