将 PHPUnit 测试类标记为被忽略
我编写了一个抽象测试用例类,该类将通过具体测试用例类进行扩展。
它从 PHPUnit_TestCase 扩展而来。
是否有方法或注释指示 Phpunit 不执行此抽象测试(但不将其标记为已跳过或不完整)?
现在 Phpunit 也运行抽象测试类,然后报告无法实例化它的错误 - 这是通过语言来实现的:抽象类无法实例化。
I have written an abstract test case class that is to be extended by concrete test case classes.
It extends from the PHPUnit_TestCase.
Is there a method or annotation that signals Phpunit to not execute this abstract test (but does not mark it as skipped or incomplete)?
Right now Phpunit runs the abstract test class as well and then reports an error that it can not instantiate it - which is by language: An abstract class can not be instantiated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需在 setUp() 上添加跳过即可:
Just add the skip on the setUp():
如果其名称为
FooTest
,则将其重命名为FooTestCase
。If it is named
FooTest
rename it toFooTestCase
.假设您要排除文件名
TestCase.php
。在我的例子中,我使用这个类作为所有测试类的抽象,它本身扩展了 PHPUnit_Framework_TestCase。
解决方案:将此添加到您的
phpunit.xml
我的
TestCase.php
示例:Assuming you want to exclude the file name
TestCase.php
.As in my case I use this class as an abstract to all my test classes which itself extends
PHPUnit_Framework_TestCase
.Solution: add this to your
phpunit.xml
My
TestCase.php
example:与 @david-harkness 所说的类似,重命名该类,因为 PHPUnit 尝试构造带有后缀
Test
的所有类。在我们的例子中,我们使用了后缀Tester
,因此:AbstractTest
变为AbstractTester
。Similar to what @david-harkness said, rename the class, since PHPUnit attempts to construct all classes with the suffix,
Test
. In our case, we went with the suffixTester
, so:AbstractTest
becomesAbstractTester
.