Zend Framework 2 Unit Tests on Jenkins not working

谁都会走 提交于 2020-01-05 03:44:09

问题


I have a zend framework 2 project and i am trying to set up my jenkins so that unit tests can be executed. Jenkins is running on ubuntu and i am developing under Windows 7 with PHPStorm.

build.xml

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

Folder structure:

  • project
    • module
      • Addressbook
      • test
        • AddressbookTest
          • Controller
            • AddressbookControllerTest.php
          • Boostrap.php
          • phpunit.xml.dist
          • TestConfig.php
    • build.xml

Jenkins Output:

phpunit:
     [exec] PHPUnit 3.7.13 by Sebastian Bergmann.
     [exec] 
     [exec] PHP Fatal error:  Class 'AddressbookTest\Bootstrap' not found in /var/lib/jenkins/workspace/Test/src/module/Addressbook/test/AddressbookTest/Controller/AddressbookControllerTest.php on line 28

PHPStorm on my local machine does this when running 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

How can i use that for jenkins?


回答1:


It looks like your include path isn't setup correctly, I wouldn't use exec directly with PHPUNIT when there's better options.

You should look into using PHING tasks with Jenkins, they work excellent together.

You then setup Jenking to trigger your PHING target to run the unit tests for you via the PHPUNIT task, an example phing target for PHPUNIT:

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


来源:https://stackoverflow.com/questions/14550150/zend-framework-2-unit-tests-on-jenkins-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!