【问题标题】:How does phpunit command make search class testing?phpunit 命令如何进行搜索类测试?
【发布时间】:2011-07-01 12:17:16
【问题描述】:

我使用窗户。 例如,我有一些网站的结构如下:

site/
    engine/
       ModelClass.php
    www/
       index.php
    tests/
       ModelCalssTest.php
phpunit.bat

phpunit.bat 应该存放在哪里运行测试 ModelClassTest.php?

【问题讨论】:

    标签: php unit-testing testing phpunit


    【解决方案1】:

    您根本不需要存储phpunit.bat。它应该在您的PATH 中。

    只需通过 PEAR 安装即可。如果您不想这样做,并且您在系统本地拥有它,或者您想要版本控制中的 phpunit 源(有些人想要),那么您的 phpunit.bat 的真正位置并不重要。项目根目录很好,vendor/phpunit/phpunit.bat 的某个地方也可以,如果你的项目根目录中有一个 ant 或 phing 或 .bat 文件可以让你说"run tests now"


    我目前观察到的“最佳实践”是将您的phpunit.xml.dist(配置文件)放在您的应用程序根目录中,这样人们就可以:

    • 获取源代码
    • 输入phpunit
    • 确保一切正常

    见:a sample project made by the phpunit author

    我还看到人们将该配置文件放在他们的“测试”文件夹中以获得“干净的项目根目录”。效果也很好。

    参考:Documentation on the phpunit xml file

    【讨论】:

    • 有点说不清楚,抱歉。如果 phpunit.bat 用于不同的项目并且它存储在 PATH 环境下,那么 phpunit.bat 将如何知道我要测试的项目是什么?
    • @Anthony you cd C:/to/your/project 并在此处输入 phpunit。它知道它是从哪里执行的。就像dir 知道你在哪个文件夹一样。这就是为什么人们通常只从 pear 安装它而不是为每个项目安装它。
    • 这确实是我需要的))非常感谢!
    【解决方案2】:

    我的 PATH 中通常有 phpunit 可执行文件,并为类似于您的测试保留一个结构化目录。然后你应该configure your phpunit using the xml file 在其中包含常用选项和最重要的引导文件,其中包含测试所需的一次性设置。如果你把 xml 文件放在测试文件夹中,你可以有这样的结构

    tests
    ├── bootstrap.php
    ├── TestEnvironment.php
    ├── application
    │   ├── controllers
    │   │   └── IndexControllerTest.php
    │   ├── forms
    │   │   └── UserTest.php
    │   ├── helpers
    │   │   └── Html2TxtTest.php
    │   └── modules
    │       └── admin
    │           └── models
    │               ├── LayoutManagerTest.php
    │               ├── ScriptOptionsTest.php
    │               ├── ServiceTest.php
    │               ├── TemplatesTest.php
    │               └── UsersFinderTest.php
    └── phpunit.xml
    

    并根据需要使用类似的命令运行测试

    phpunit # run all tests
    phpunit application # run all tests inside application folders
    phpunit application/forms/UserTest.php # run all tests inside the given file
    

    所以,只要你在 PATH 中有 phpunit,运行它就没有问题,如果你的 PATH 中没有它,请考虑将它放在测试文件夹中并从那里运行它。

    这在 Unix 环境中运行良好,但它也应该在 Win32 上运行。

    【讨论】:

    • Tnx。 phpunit.bat(或 phpunit.sh)存储在您的示例路径树中的什么位置?
    • 你应该把它放在你的路径中。在 Windows 上,您可以在提示符上执行 echo %PATH% 来发现它(我不记得 PATH on win)。如果您不想这样做,请将其保存在测试文件夹下,但这样您就必须将其复制到不同的项目中。
    猜你喜欢
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    • 2010-10-19
    • 2014-05-13
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多