phpunit - 为什么 PHPUnit 没有启动我的自定义测试?
问题描述
如PHPUnit doc中所述,您可以实现PHPUnit\Framework\Test
编写自定义测试。
听起来不错,但是如何将这些测试作为我的测试套件的一部分启动?
给定以下测试目录:
+tests/
|- NormalTestExtendingTestCaseTest.php
|- CustomTestImplementingTest.php
phpunit.xml
还有我的 phpunit.xml 文件:
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="My Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
只有 NormalTestExtendingTestCaseTest.php 由 PHPUnit 执行。
CustomTestImplementingTest.php
<?php
use PHPUnit\Framework\TestCase;
class CustomTestImplementingTest implements PHPUnit\Framework\Test
{
public function count()
{
return 1;
}
public function run(PHPUnit\Framework\TestResult $result = null)
{
if ($result === null) {
$result = new PHPUnit\Framework\TestResult;
}
$result->startTest($this);
// do something
$result->endTest($this, $stopTime);
return $result;
}
}
解决方案
检查您的类是否具有正确的继承、正确的名称方法(以“test”开头)和正确的命名空间。
您可能必须运行 composer dump-autoload。
推荐阅读
- scala - ExceptionInInitializerError Spark Streaming Kafka
- javascript - RethinkDB:Javascript - 如何删除嵌套对象
- r - 将多个参数传递给渲染函数以编织 html?
- asp.net-identity - 如何使用 .netcore 2.0 身份和 cookie 身份验证正确设置会话超时
- javascript - Firebase Nodejs 错误的返回值
- json - 让两个平均堆栈应用程序在同一页面/端口号上运行
- javascript - 使用 Promise.all() 获取带有 await 语句的 url 列表
- google-chrome - Chrome 在每次点击网站时都会通过 Digest 身份验证要求用户/密码,而 IE、Edge 和 Firefox 则不需要
- php - Braintree webhook 成功通知到数据库
- java - 如何使用由另一个 Jenkins 插件创建的类实例