【问题标题】:How to test every module in my application phpunit - zend framework 2如何测试我的应用程序 phpunit 中的每个模块 - zend 框架 2
【发布时间】:2013-10-02 13:29:04
【问题描述】:

我已经对我的应用程序模块和其他模块进行了测试。他们工作正常,但我想同时运行所有测试(应用程序模块和其他模块)以为詹金斯生成三叶草报告。我该怎么办??创建另一个配置文件来调用其他配置文件??

---编辑---

我对每个模块 bootstrap.php 都有相同的代码,我想对每个模块使用相同的代码以避免代码重复。现在我有两个模块应用程序和问题,当我运行 phpunit 时它会抛出这个错误:

**.PHP Fatal error:  Class 'ProblemTest\Bootstrap' not found ....**

Application 模块的测试工作正常,但 Problem 模块的测试不适用于 phpunit_bootstrap.php 文件中的命名空间声明。

我的应用程序测试使用此声明:

<?php
   namespace ApplicationTest\Controller;
   use ApplicationTest\Bootstrap; ....

我的问题测试使用这个声明:

<?php
    namespace ProblemTest\Controller;
    use ProblemTest\Bootstrap;

这是我的 phpunit.xml

<phpunit bootstrap="phpunit_bootstrap.php">
<testsuites>
    <testsuite name="ALL">
        <directory>module/Application/test</directory>
        <directory>module/Problem/test</directory>
    </testsuite>
</testsuites>

这是我的 phpunit_bootstrap.php

<?php
 namespace ApplicationTest;

我现在要一起运行所有测试的问题是如何为每个测试包含相同的引导程序以避免该异常。

【问题讨论】:

    标签: php testing jenkins zend-framework2 phpunit


    【解决方案1】:

    您可以创建一个测试套件来同时运行一组单独的测试组。在您的 phpunit.xml.dist 文件中:

    <phpunit bootstrap="phpunit_bootstrap.php">
        <testsuites>
            <testsuite name="all">
                <directory>./</directory>
            </testsuite>
            <testsuite name="ALL">
                <directory>/path/to/module1tests</directory>
                <directory>/path/to/module2tests</directory>
                <directory>/path/to/module3tests</directory>
                <exclude>/path/to/module4tests</exclude>
            </testsuite>
            <testsuite name="module1only">
                <directory>./module1tests</directory>
            </testsuite>
        </testsuites>
    

    然后你可以运行它:/path/to/phpunit --testsuite="ALL"

    【讨论】:

    • 有办法为每个模块设置引导程序吗??
    • @user1835922:是的,通过在 XML 文件中指定测试运行程序的引导文件而不是在 XML 文件中。
    【解决方案2】:

    我还不能发表评论,如果您不想单独命名每个模块,可以在 zend framework 2 + phpunit + multiple modules + continuous integration 找到另一个解决方案。

    【讨论】:

      猜你喜欢
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 2012-10-10
      相关资源
      最近更新 更多