简体   繁体   English

PHPUnit:如何包括文件以使用通配符进行测试

[英]PHPUnit: How to include files for testing using wildcards

This seems like a really straightforward thing to do - identify the files for testing with phpunit using a wildcard. 这似乎是一件非常简单的事情-使用通配符标识要用phpunit测试的文件。 For example, here's my test directory: 例如,这是我的测试目录:

/test/model/v11_CountryTest.php
/test/model/v11_IndustryTest.php
/test/model/v11_UserTest.php
/test/model/v12_OrgTest.php

/test/model/factory/v11_CountryTest.php
/test/model/factory/v12_OrgTest.php

As you can see I have a model including some factories. 如您所见,我有一个包含一些工厂的模型。 Some of my model has been updated to Ver 12 (ie v12_OrgTest.php). 我的某些模型已更新至Ver 12(即v12_OrgTest.php)。 I would like PHPUnit to run all the v12 tests, but not the v11 ones. 我希望PHPUnit运行所有v12测试,但不运行v11测试。 Is there a way to do this? 有没有办法做到这一点?

I have tried simply phpunit v12*.php on the command line but that doesn't work. 我已经在命令行上尝试了phpunit v12*.php ,但这是行不通的。 Also, I tried specifying the wildcard in a <file> tag in the phpunit.xml file (under the particular test suite), with no success. 另外,我尝试在phpunit.xml文件(在特定的测试套件下)的<file>标记中指定通配符,但没有成功。

Per the manual, it looks like I can use the <groups> tag but it would mean editing each of the test files. 按照手册,看起来我可以使用<groups>标记,但这意味着编辑每个测试文件。 I'll do this if required, but would like to know if there is an easier way. 如果需要,我会做,但是想知道是否有更简单的方法。

OK, so it turns out that you can flag entire classes as belonging to a group, with the following code comments: OK,事实证明您可以使用以下代码注释将整个类标记为属于一个组:

/**
 * @group GroupName
 */

Given that it's so easy, there is hardly any need to be able to use wildcards in file selection. 由于它是如此简单,因此几乎不需要在文件选择中使用通配符。 Thanks Sebastian! 谢谢塞巴斯蒂安!

In the documentation you can find all the command line options. 在文档中,您可以找到所有命令行选项。 One of the options is "filter", where you can pass an string which PHPUnit will use to filter the tests to execute, choosing only the test cases that match your string. 选项之一是“过滤器”,您可以在其中传递一个字符串,PHPUnit将使用该字符串来过滤要执行的测试,仅选择与您的字符串匹配的测试用例。 If you've used namespacing with the version "v12", I think you could filter the desired tests, since PHPUnit uses the whole name of the method (with Namespace and class name) 如果您使用的命名空间版本为“ v12”,我认为您可以过滤所需的测试,因为PHPUnit使用方法的全名(带有命名空间和类名)

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

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