【问题标题】:Zend Framework 2 Unit Tests on Jenkins not workingJenkins 上的 Zend Framework 2 单元测试不起作用
【发布时间】:2013-01-11 02:09:33
【问题描述】:

我有一个 zend 框架 2 项目,我正在尝试设置我的 jenkins,以便可以执行单元测试。 Jenkins 在 ubuntu 上运行,我正在使用 PHPStorm 在 Windows 7 下开发。

构建.xml

<target name="phpunit" description="Run unit tests with PHPUnit">
    <exec executable="phpunit" failonerror="true">
        <arg value="${basedir}/module/Addressbook/test"/>
    </exec>
</target>

文件夹结构:

  • 项目
    • 模块
      • 通讯录
      • 测试
        • 通讯录测试
          • 控制器
            • AddressbookControllerTest.php
          • Boostrap.php
          • phpunit.xml.dist
          • TestConfig.php
    • build.xml

Jenkins 输出:

php单元: [执行] Sebastian Bergmann 的 PHPUnit 3.7.13。 [执行] [exec] PHP 致命错误:在第 28 行的 /var/lib/jenkins/workspace/Test/src/module/Addressbook/test/AddressbookTest/Controller/AddressbookControllerTest.php 中找不到类 'AddressbookTest\Bootstrap'

我本地机器上的 PHPStorm 在运行 phpunit.xml.dist 时会这样做

D:\Zend\ZendServer\bin\php.exe -d auto_prepend_file=D:/Zend/Apache2/htdocs/demoshop/vendor/autoload.php C:\Users\ChristianB\AppData\Local\Temp\ide-phpunit.php --configuration D:/Zend/Apache2/htdocs/demoshop/module/Addressbook/test/phpunit.xml.dist

我如何将它用于詹金斯?

【问题讨论】:

  • 我帮不上忙。但是要从其他人那里获得帮助,他们肯定需要您的引导代码。错误很明显,找不到类。这表明您的引导失败/错误。

标签: jenkins phpunit zend-framework2


【解决方案1】:

您的包含路径似乎设置不正确,如果有更好的选择,我不会直接将 exec 与 PHPUNIT 一起使用。

您应该考虑将 PHING 任务与 Jenkins 一起使用,它们可以很好地协同工作。

然后您设置 Jenking 以触发您的 PHING 目标,以通过 PHPUNIT 任务为您运行单元测试,这是 PHPUNIT 的示例 phing 目标:

<target name="phpunit">
    <phpunit bootstrap="${srcdir}/tests/bootstrap.php">
        <formatter todir="${builddir}/reports" type="xml"/>
        <batchtest>
            <fileset dir="${srcdir}/tests">
                <include name="**/*Test*.php"/>
                <exclude name="**/Abstract*.php"/>
                <exclude name="${srcdir}/vendor/**"/>
            </fileset>
        </batchtest>
    </phpunit>
    <!-- 
        Generate a report from the XML data created.. 
        note: error when using format="frames"
    --> 
    <phpunitreport infile="${builddir}/reports/testsuites.xml" 
        format="noframes" 
        todir="${builddir}/reports/tests"
    />

</target>

【讨论】:

  • 我已经修好了,谢谢:) 成功了
猜你喜欢
  • 2012-12-25
  • 1970-01-01
  • 2014-12-29
  • 1970-01-01
  • 2013-05-26
  • 1970-01-01
  • 2013-09-18
  • 1970-01-01
  • 2013-10-12
相关资源
最近更新 更多