将 PHPT 测试用例与 PHPUnit 集成 [英] Integrate PHPT test cases with PHPUnit

查看:24
本文介绍了将 PHPT 测试用例与 PHPUnit 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 PHPUnit 运行我的 PHPT 测试用例 并整合通过/失败状态进入整体指标?我已经知道如何使用 run-phpt 运行这些测试 从命令行,但我想在 PHPUnit 中运行它们和我的其他测试.

How can I get PHPUnit to run my PHPT test cases and integrate the pass/fail status into the overall metrics? I am already aware of how to run these tests using run-phpt from the command line, but I want to run them from within PHPUnit with my other tests.

我知道 PHPUnit_Extensions_PhptTestCase 存在,但我找不到任何有关如何使用它的示例.

I'm aware that the PHPUnit_Extensions_PhptTestCase exists but I couldn't find any samples on how to use it.

推荐答案

虽然本文的重点是博文关于测试文件上传 是描述如何编写 PHPT 测试,它在文章末尾展示了如何将它们集成到 PHPUnit 中.简而言之,您将 .phpt 文件的绝对路径传递给父构造函数.

While the main point of this blog post about testing file uploads is to describe how to write PHPT tests, it shows how to integrate them into PHPUnit at the end of the post. In short, you pass the absolute path to the .phpt file to the parent constructor.

<?php
require_once 'PHPUnit/Extensions/PhptTestCase.php';

class UploadExampleTest extends PHPUnit_Extensions_PhptTestCase {
    public function __construct() {
        parent::__construct(__DIR__ . '/upload-example.phpt');
    }
}

或者,您可以使用 PHPUnit_Extensions_PhptTestSuite 类,该类将目录作为其第一个构造函数参数,然后搜索该目录中的所有 *.phpt 文件.

Alternatively, you can use the PHPUnit_Extensions_PhptTestSuite class, that takes a directory as its first constructor argument and then searches for all *.phpt files within this directory.

这篇关于将 PHPT 测试用例与 PHPUnit 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆