测试多个文件夹

发布于 2024-10-28 19:15:36 字数 1197 浏览 2 评论 0原文

我在项目中使用 PHPUnit 3.5.12、netbean 6.9 和 git 子模块。

所以我的文件夹架构如下所示:

lib/
lib/submodule1
lib/submodule1/src
lib/submodule1/tests
lib/submodule2
lib/submodule2/src
lib/submodule2/tests
src/
tests/

考虑到我的主测试文件夹(包含 phpunit_netbean.xml 和 bootstrap.php)位于 /tests/ 文件夹中;我怎样才能在 /lib/*/tests/ 中运行测试?

我查看了测试套件,但无法让它工作。到目前为止,我已经在tests/phpunit_netbean.xml 文件中尝试了以下配置:

<?xml version="1.0"?>
<phpunit
    bootstrap="./bootstrap.php"
    strict="true"
    stopOnError="false"
    stopOnFailure="false"
    stopOnIncomplete="false"
    stopOnSkipped="false"
    colors="false"
    verbose="true"
    >

    <testsuites>
        <testsuite name="modules">
            <directory>../lib/*</directory>
        </testsuite>
    </testsuites>

</phpunit>

当我在Netbean 中按ALT+F6 时,我只运行/tests 中的测试。同样的事情:

/tests$ phpunit -c phpunit_netbean.xml --testdox ./
enter code here

另外,我已经尝试过:

/tests$ phpunit -c phpunit_netbean.xml --testdox --loader modules ./
PHPUnit 3.5.12 by Sebastian Bergmann.

Could not use "modules" as loader.

I use PHPUnit 3.5.12, netbean 6.9, and git submodules in my project.

So my folder architecture looks like that:

lib/
lib/submodule1
lib/submodule1/src
lib/submodule1/tests
lib/submodule2
lib/submodule2/src
lib/submodule2/tests
src/
tests/

Considering that my main test folder (with phpunit_netbean.xml and bootstrap.php) is in the /tests/ folder; How can I be able to run the tests in /lib/*/tests/ too ?

I've look at testsuite, but I'm unable to get it working. So far I've tried the following configuration in my tests/phpunit_netbean.xml file:

<?xml version="1.0"?>
<phpunit
    bootstrap="./bootstrap.php"
    strict="true"
    stopOnError="false"
    stopOnFailure="false"
    stopOnIncomplete="false"
    stopOnSkipped="false"
    colors="false"
    verbose="true"
    >

    <testsuites>
        <testsuite name="modules">
            <directory>../lib/*</directory>
        </testsuite>
    </testsuites>

</phpunit>

And when I hit ALT+F6 in Netbean, I only have the tests from /tests that are run. Same thing with:

/tests$ phpunit -c phpunit_netbean.xml --testdox ./
enter code here

Also, I've tried this:

/tests$ phpunit -c phpunit_netbean.xml --testdox --loader modules ./
PHPUnit 3.5.12 by Sebastian Bergmann.

Could not use "modules" as loader.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞄了个咪的 2024-11-04 19:15:36

查看PHPUnit 配置文件的附录。您可以告诉 PHPUnit 要包含哪些文件夹:

<testsuites>
    <testsuite name="Submodules">
        <directory suffix="Test.php">../lib/*</directory>
    </testsuite>
</testsuites>

当您运行此命令时,PHPUnit 应该递归地迭代 lib 中的所有文件夹,并将所有以 Test.php 结尾的文件视为 UnitTests。测试套件的名称无关紧要。为了简化 XML 文件的创作,考虑使用我的 phpunit-schema 文件

PHPUnit 手册章节:使用文件系统。 Netbeans 有一个输入对话框,您可以在其中指定 phpUnit.xml 和任何自定义 TestSuite 类的路径。

这是一个示例项目:https://github.com/gooh/sample

C:\Users\Gordon\Desktop\demo\tests>phpunit --testdox
PHPUnit 3.5.13 by Sebastian Bergmann.

A
 [x] One

B
 [x] One

My
 [x] One

Have a look at the Appendix for your PHPUnit config file. You can tell PHPUnit which folders to include:

<testsuites>
    <testsuite name="Submodules">
        <directory suffix="Test.php">../lib/*</directory>
    </testsuite>
</testsuites>

When you run this, PHPUnit should recursively iterate over all folders in lib and consider all files ending in Test.php as UnitTests. The name of the testsuite is irrelevant. To ease authoring of the XML file, consider using my phpunit-schema file.

There is some additional information to this in the PHPUnit Manual Chapter: Composing a Test Suite Using the Filesystem . Netbeans has an input dialog in which you can specify the path to the phpUnit.xml and any custom TestSuite Class.

Here is an example project: https://github.com/gooh/sample

C:\Users\Gordon\Desktop\demo\tests>phpunit --testdox
PHPUnit 3.5.13 by Sebastian Bergmann.

A
 [x] One

B
 [x] One

My
 [x] One
一曲琵琶半遮面シ 2024-11-04 19:15:36

让我们创建一个测试用例:

mkdir project
mkdir project/tests
mkdir project/modules/
mkdir project/modules/a/
mkdir project/modules/a/tests/
mkdir project/modules/b/
mkdir project/modules/b/tests/

echo "<?php class MyTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/tests/MyTest.php
echo "<?php class MyTwoTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/a/tests/MyTwoTest.php
echo "<?php class MyThreeTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/b/tests/MyThreeTest.php


tree
.
`-- project
    |-- modules
    |   |-- a
    |   |   `-- tests
    |   |       `-- MyTwoTest.php
    |   `-- b
    |       `-- tests
    |           `-- MyThreeTest.php
    `-- tests
        `-- MyTest.php

如果您现在刚刚运行phpunit 项目,它将执行这些文件夹中的所有测试。所以不需要任何进一步的配置。

如果您的 /src/ 文件夹中有以 *Test.php 结尾的女孩,唯一可能会困扰您的事情是,如果您不这样做,据我所知,您不会遇到任何问题。

phpunit project/
PHPUnit 3.5.11 by Sebastian Bergmann.

...

Time: 0 seconds, Memory: 2.75Mb

Let's create a testcase:

mkdir project
mkdir project/tests
mkdir project/modules/
mkdir project/modules/a/
mkdir project/modules/a/tests/
mkdir project/modules/b/
mkdir project/modules/b/tests/

echo "<?php class MyTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/tests/MyTest.php
echo "<?php class MyTwoTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/a/tests/MyTwoTest.php
echo "<?php class MyThreeTest extends PHPUnit_Framework_TestCase { public function testOne() { \$this->assertTrue(true); } } " > project/modules/b/tests/MyThreeTest.php


tree
.
`-- project
    |-- modules
    |   |-- a
    |   |   `-- tests
    |   |       `-- MyTwoTest.php
    |   `-- b
    |       `-- tests
    |           `-- MyThreeTest.php
    `-- tests
        `-- MyTest.php

If you now just run phpunit project it will execute ALL the tests in those folders. So no need for any further configuration.

The only thing that could bite you if you have lasses in your /src/ folders that end in *Test.php, if you don't do that you will not have any issues as far as i can tell.

phpunit project/
PHPUnit 3.5.11 by Sebastian Bergmann.

...

Time: 0 seconds, Memory: 2.75Mb
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文