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

时间:2021-03-21 01:20:36

After created a job for my Kohana-based project in Jenkins, I cannot figure out how to config the job in order to run unit tests. Basically I used the template from http://jenkins-php.org/, but Kohana has its unique settings which does not allow me to run unit tests as normal php projects. Since phpunit command is not run from CLI, I kept getting errors:

在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

In the build.xml, I have

在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>

In the application/tests/phpunit.xml, I got

在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>

Anyone can share your experience on setting Kohana job in Jenkins? Thanks!

任何人都可以分享你在詹金斯设立Kohana工作的经验吗?谢谢!

Update: running the same test from CLI, it works in Windows XP with PHPUnit 3.6.11, but it doesn't work in Ubuntu Server with PHPUnit 3.7.18

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

1 个解决方案

#1


0  

I solve the problem by these two steps:

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

sudo pear update-channels
sudo pear upgrade-all

It updates all the packages including PHPUnit.

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

#1


0  

I solve the problem by these two steps:

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

sudo pear update-channels
sudo pear upgrade-all

It updates all the packages including PHPUnit.

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