php - 如何配置 Jenkins 作业以运行单元测试

标签 php unit-testing jenkins continuous-integration kohana

在 Jenkins 中为基于 Kohana 的项目创建作业后,我不知道如何配置该作业以运行单元测试。基本上我使用了 http://jenkins-php.org/ 中的模板,但 Kohana 有其独特的设置,不允许我像普通的 php 项目一样运行单元测试。由于 phpunit 命令不是从 CLI 运行的,所以我不断收到错误:

 [exec] ErrorException [ 1 ]: Call to undefined method Log::instance() ~ SYSPATH/classes/kohana/core.php [ 336 ]
 [exec] PHP Notice:  Undefined index: REMOTE_ADDR in /var/lib/jenkins/jobs/Construct-A-Cost Deployment Build/workspace/application/bootstrap.php on line 70
 [exec] PHP Fatal error:  Call to undefined method Log::instance() in /var/lib/jenkins/jobs/Construct-A-Cost Deployment Build/workspace/system/classes/kohana/core.php on line 336

在 build.xml 中,我有

 <target name="phpunit" description="Run unit tests with PHPUnit">
   <mkdir dir="${basedir}/application/cache" />
   <mkdir dir="${basedir}/application/logs" />
   <exec dir="${basedir}/application/tests" executable="phpunit" failonerror="true" />
 </target>

在application/tests/phpunit.xml中,我得到了

<phpunit colors="true" bootstrap="../../modules/unittest/bootstrap.php">
<testsuites>
    <testsuite name="Calculation Tests">
        <file>./classes/controller/calculation.php</file>
    </testsuite>
</testsuites>
</phpunit>

任何人都可以分享您在 Jenkins 中设置 Kohana 工作的经验吗?谢谢!

更新:从 CLI 运行相同的测试,它在带有 PHPUnit 3.6.11 的 Windows XP 中工作,但在带有 PHPUnit 3.7.18 的 Ubuntu Server 中不起作用

最佳答案

我通过这两个步骤解决了这个问题:

sudo pear update-channels
sudo pear upgrade-all

它更新所有包,包括 PHPUnit。

关于php - 如何配置 Jenkins 作业以运行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15943714/

相关文章:

android - 由于内部错误 : Running tests on UI thread,测试启动失败

javascript - 如何使用 Jasmine 2.4.1(独立)设置基本的 Javascript 测试?

php - Composer - 仅在开发环境中运行脚本

php - 以太平洋标准时间显示时间

php - 如何在laravel http客户端api调用中分离基本URL和端点?

php - 如何从 mysql 选择并回显图像

php - 如何在一个变量中发布两个字段值

java - 接收 tdd url 测试的空输出

maven - Jenkins 和 maven-compiler-plugin?

jenkins - 如何从 Jenkinsfile 获取 "Scan Repository Now"