如何配置Jenkins作业以运行单元测试
问题描述:
在Jenkins中为我的基于Kohana的项目创建作业后,我无法弄清楚如何配置作业以运行单元测试。基本上我使用http://jenkins-php.org/的模板,但Kohana有其独特的设置,不允许我像正常的PHP项目一样运行单元测试。由于PHPUnit的命令不是从CLI运行,我一直得到错误:如何配置Jenkins作业以运行单元测试
[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>
在应用/测试/ 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相同的测试,它工作在Windows XP中使用PHPUnit 3.6.11,但它并没有在Ubuntu服务器PHPUnit的工作3.7.18
答
我这些解决问题两步:
sudo pear update-channels
sudo pear upgrade-all
它更新所有包,包括PHPUnit。
看起来像jenkins调用与kohana日志类同名的日志类。好像你遇到了一个名称冲突... – ITroubs 2013-04-11 14:42:13
试着看看这里,它可能会帮助http://blog.loftdigital.com/posts/jenkins-ci-and-php 顺便说一句,它从命令行运行phpunit 。 – 2013-04-11 23:29:54
@ZdenekMachek,感谢从CLI提示运行phpunit,没有想到这一点,它可能能够解决问题,因为我从命令行运行phpunit时没有遇到错误。绝对会尝试一下! – Kevin 2013-04-12 01:14:33