简体   繁体   English

如何告诉PHPUnit测试的位置?

[英]How do I tell PHPUnit where my tests are located?

After spending several hours today searching and seeing several people having the same issue, I thought I turn to SO. 今天花了几个小时搜索并看到几个人有相同的问题后,我认为我转向了。

I run a WAMP stack; 我运行一个WAMP堆栈; I have successfully installed PEAR and PHPUnit 3.6 using PEAR. 我已经使用PEAR成功安装了PEAR和PHPUnit 3.6。 I'm able to run phpunit over command line. 我可以通过命令行运行phpunit。

My WAMP folder is located at C:\\wamp - I have several www folders - for sake of example let's say I have an MVC application located at C:\\www\\myproject. 我的WAMP文件夹位于C:\\ wamp-我有几个www文件夹-举例来说,我有一个MVC应用程序位于C:\\ www \\ myproject。

/myproject
    /application
        /controllers
        /models
        /modules
            /forum
                /controllers
                /models
                /tests
                /views
        /views
    /public_html
    /tests

I'd like to know where PHPUnit is looking when I run something like 我想知道当我运行类似东西时PHPUnit在哪里

phpunit ArrayTest phpunit ArrayTest

Any help greatly appreciated, Thanks 任何帮助,不胜感激,谢谢

phpunit --help
PHPUnit 3.6.9 by Sebastian Bergmann.

Usage: phpunit [switches] UnitTest [UnitTest.php]
       phpunit [switches] <directory>

This means you have two options: 这意味着您有两个选择:

If you want to execute one test you can say: 如果要执行一项测试,可以说:

phpunit myTest /path/to/my/test/php

or you can say 或者你可以说

phpunit /path/to/my/projects/tests

and it will recursively scan the directory for all files ending in Test.php and execute all tests in those folders. 它将以递归方式扫描目录中所有以Test.php结尾的文件,并在这些文件夹中执行所有测试。

This is outlined in the phpunit documentation regard test suite organisation and in the help output and to be honest with you: I've never seen anyone having an issue with that so far :) phpunit documentation regard test suite organisation以及帮助输出中对此进行了概述,老实说:到目前为止,我从未见过有人对此有问题:)


What is usually done is that people put a phpunit.xml.dist file in their project root. 通常要做的是,人们将phpunit.xml.dist文件放入其项目根目录中。

In that file you can specify everything regard test location, test suite bootstrap and other configuration options. 在该文件中,您可以指定有关测试位置,测试套件引导程序和其他配置选项的所有信息。 Check the xml file docs

This allows you to just type phpunit and the tests will run. 这使您只需键入phpunit运行测试。

It is looking for your /tests in the current directory. 它正在当前目录中查找/ tests。 Change (cd ..) to the directory containing your project and run phpunit. 更改(cd ..)到包含您的项目的目录,然后运行phpunit。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM