【问题标题】:How to configure a Jenkins job to run a unit test如何配置 Jenkins 作业以运行单元测试
【发布时间】:2013-04-03 08:22:29
【问题描述】:

在 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 中运行

【问题讨论】:

  • 看起来 jenkins 调用了一个与 kohana 日志类同名的日志类。好像你遇到了名字冲突......
  • 尝试看看这里,它可能会有所帮助blog.loftdigital.com/posts/jenkins-ci-and-php 顺便说一下它从命令行运行 phpunit。
  • @ZdenekMachek,感谢您从 CLI 提示运行 phpunit,没有想到这一点,它可能能够解决问题,因为从命令行运行 phpunit 时不会出错。一定会试一试的!
  • 一些更新:从 CLI 运行相同的测试,它可以在带有 PHPUnit 3.6.11 的 Windows XP 中工作,但它不能在带有 PHPUnit 3.7.18 的 Ubuntu Server 中工作,我真的无法弄清楚:-(

标签: php unit-testing jenkins continuous-integration kohana


【解决方案1】:

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

sudo pear update-channels
sudo pear upgrade-all

它会更新所有的包,包括 PHPUnit。

【讨论】:

    猜你喜欢
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    相关资源
    最近更新 更多