沃梦达 / 编程问答 / php问题 / 正文

为 PHPUnit 配置文件名

Configuring File Names for PHPUnit(为 PHPUnit 配置文件名)

本文介绍了为 PHPUnit 配置文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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 的自动化测试
   文件2.php
   File2.php.test - File2.php的自动化测试

应用2/
   ANOTHER_CLASS.class
   ANOTHER_CLASS.class.test
   DifferentFile.php - 应用程序文件
   DifferentFile.php.test - File.php 的自动化测试

库/
   UTIL/
      SHARED_CLASS.class
      SHARED_CLASS.class.test
   视觉/
      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 配置部分文档涉及测试组织

你想要的是:

 <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 配置文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:为 PHPUnit 配置文件名

基础教程推荐