问题描述
我是PHPUnit的新用户,并且我将现有的测试(断言)转换为PHPUnit框架,以提供更好的测试环境和代码覆盖范围.但是,我需要知道如何尝试使PHPUnit与我们的测试代码结构一起使用.
I am a new user of PHPUnit, and I am converting our existing tests (asserts) into the PHPUnit framework to provide a better test environment and code coverage. However, I need to know how to try to get PHPUnit working with our testing code structure.
我们的项目目录类似于以下内容:
应用程序1/
CREDIT_CARD.class-CREDIT_CARD的类命名约定
CREDIT_CARD.class.test-CREDIT_CARD.class的自动化测试
File.php-应用程序文件
File.php.test-File.php的自动化测试
File2.php
File2.php.test-File2.php的自动化测试
应用程序2/
ANOTHER_CLASS.class
ANOTHER_CLASS.class.test
DifferentFile.php-应用程序文件
DifferentFile.php.test-File.php的自动化测试
lib/
UTIL/
SHARED_CLASS.class
SHARED_CLASS.class.test
VISUAL/
VISUAL_TOOL.class
VISUAL_TOOL.class.test
我需要知道如何配置PHPUnit测试,以便可以在lib/UTIL/ .test(使用setUp()方法加载类文件)中然后在lib/VC/中运行测试.测试,然后(如果成功)进行Application1和Application2测试.我看到提到了一个PHPUnit_xml文件和一个引导文件,但是我找不到参考模板来查看这些是否是我所需要的.任何帮助,将不胜感激.
Our project directories are similar to the following:
Application1/
CREDIT_CARD.class - Class naming convention for CREDIT_CARD
CREDIT_CARD.class.test - Automated Tests for CREDIT_CARD.class
File.php - Application File
File.php.test - Automated tests for File.php
File2.php
File2.php.test - Automated tests for File2.php
Application2/
ANOTHER_CLASS.class
ANOTHER_CLASS.class.test
DifferentFile.php - Application File
DifferentFile.php.test - Automated tests for File.php
lib/
UTIL/
SHARED_CLASS.class
SHARED_CLASS.class.test
VISUAL/
VISUAL_TOOL.class
VISUAL_TOOL.class.test
I need to know how to configure the PHPUnit tests so I can run the tests in lib/UTIL/.test (which load the class file using the setUp() method) then the lib/VC/.test, followed (if successful) by the Application1 and Application2 tests. I saw mention of a PHPUnit_xml file and a bootstrap file, but I can not find a reference template to see if these are what I need. Any help would be appreciated.
我知道文档除了文件名之外还引用了test.php,但我希望不必更改我们的结构和命名约定,因为我希望能够混合运行多个文件,直到它们被全部转换为PHPUnit框架.更改名称将导致我们公司的程序更改以及对开发人员的培训,我试图避免这种情况.
I know the documentation refers to a test.php addition to the file names, but I am hoping to not have to change our structure and naming conventions as I would like to be able to run a mix of the files until they are all converted over to the PHPUnit framework. Changing names will cause a procedure change in our company and training for the developers, which I am trying to avoid.
在此先感谢您的帮助.
推荐答案
因此,您有一个名为Foo.class.test
的文件,而不是PHPUnit默认的FooTest.php
吗?
So you have files named Foo.class.test
instead of the PHPUnit default FooTest.php
?
这不是什么大问题,因为PHPUnit允许您配置将哪些文件后缀视为测试". Test.php
只是默认设置.
That shouldn't be a big problem as PHPUnit allows you to configure what file suffixes are to be treated as "tests". The Test.php
is just the default.
看看 xml config part of the docs regard test organisation
您想要的是:
<testsuites>
<testsuite name="Our new shiny phpunit test Suite">
<directory suffix=".test">./sourceFolder</directory>
</testsuite>
</testsuites>
然后,PHPUnit将扫描源文件夹,包括所有以.class.test
结尾的文件,而其他文件保持不变.
PHPUnit will then scan through the source folder including all files that end in .class.test
and leaving the other files as is.
这篇关于为PHPUnit配置文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!