如何排除文件从PHPUnit测试套件在XML配置? [英] How to exclude file from PHPUnit test suite in xml config?

查看:418
本文介绍了如何排除文件从PHPUnit测试套件在XML配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下非常简单的PHPUnit的XML配置:

I have following, very simple, XML config for PHPUnit:

<phpunit bootstrap="/_tests/TestAutoload.php">
    <testsuites>
        <testsuite name="Unit Tests">
            <directory suffix=".php">_tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

如何从测试套件中排除此目录中的某些文件?我尝试了< exclude> < blacklist> ,但它似乎并不工作。也找不到任何其他文档,除了 phpunit.de 一个, t提到任何事情。否则,这个配置工作完美。

How to exclude certain file in this directory from test suite? I tried <exclude> and <blacklist>, but it doesn't seem to work in this context. Also couldn't find any other documentation than phpunit.de one, which doesn't mention anything about it. Else than that, this config works perfectly.

推荐答案

有很多方法不能运行一个特定的测试 - 一个黑名单,所以它永远不会运行可能不是这样的方式 - 更改它意味着编辑黑名单,你会经常结束反弹和退出版本控制。

There are a number of ways to not run a particular test - putting it into a blacklist so it's never run may not be the way - as changing it means editing the blacklist, and you'll often endup bouncing it in and out of version control.

还有其他几种更合适的方法:

如果测试尚未准备好运行:

$this->markTestIncomplete('This test has not been implemented yet.');

如果存在外部原因,则不应运行,请跳过:

if (!extension_loaded('mysqli')) {
    $this->markTestSkipped('The MySQLi extension is not available.');
}

您也可以将其放入 setUp 函数,因此它将跳过测试类中的所有测试。

You can also put that into the setUp() function, so it will skip all the tests in a test-class.

您可以使测试依赖于前一个测试成功:

You can make a test dependant on a previous one succeeding:

public function testEmpty()
{
    $stack = array();
    $this->assertTrue(empty($stack));
    return $stack;   // also sends this variable to any following tests - if this worked
}
/**
 * only runs if testEmpty() passed
 *
 * @depends testEmpty
 */
public function testPush(array $stack)
{
}

/**
 * @group database
 * @group remoteTasks
 */
public function testSomething()
{
}

testSomething()现在分为两组,并且如果在命令行(或在config.xml中) - exclude-group 参数中添加。它不会运行。同样,您可以只运行属于特定组的测试 - 以特性或错误报告命名。

testSomething() is now in two groups, and if either is added on the command line (or in the config.xml) --exclude-group parameter. it won't be run. Likewise, you could run only tests that belong to a particular group - say named after a feature, or bug report.

这篇关于如何排除文件从PHPUnit测试套件在XML配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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