0

我想用 Grunt 自动化 CakePHP 测试,发现grunt.loadNpmTasks('grunt-phpunit');它可以自动化 PHPUnit,但我确定它不能处理cake test

我对cake test从 Grunt 运行的解决方案也很满意,但我对运行 PHPUnit 命令的方法非常感兴趣,该命令可以执行 CakePHP 测试。

编辑:我正在使用 CakePHP 的当前稳定版本,现在是 2.5.4。

4

2 回答 2

0

我假设 grunt-phpunit 需要一个默认的标准 phpunit 执行,如果这是真的,你不能那样运行它,你必须熟练使用这个工具。我猜它正在解析测试输出。CakePHP2 不允许您像现在使用 CakePHP 和其他库那样简单地运行“phpunit”。CakePHP2 扩展了 phpunit 测试类,所以我怀疑你是否可以在不使用 cakephp 测试外壳的情况下运行它们。

我们使用 Jenkins 和我们自己定制的脚本来自动化测试。

于 2014-09-09T17:50:10.063 回答
0

我找到了解决方案。

在一个日本网站上,我发现了一个有趣的想法:

首先我必须复制webroot/test.phpas 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 运行我的测试。

于 2014-11-07T10:32:21.833 回答