gpt4 book ai didi

PHPUnit Eclipse 配置 : No Tests Found

转载 作者:行者123 更新时间:2023-12-04 05:08:34 25 4
gpt4 key购买 nike

在尝试使用 PHPUnit 将 Eclipse 设置为单元测试库时,我在尝试运行一个简单的测试用例时遇到了困难。作为引用,我关注了 this在使用 PHPUnit/Xdebug/Makegood 设置 Eclipse 的教程中,与给出的指南的唯一偏差是为 PHPUnit/Makegood 设置以下配置文件:

config.xml:
<phpunit backupGlobals="true"
backupStaticAttributes="false"
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
strict="false"
verbose="false">
<testsuites>
<testsuite name="My Test Suite">
<directory suffix=".php">/path/to/application/tests/</directory>
</testsuite>
</testsuites>
</phpunit>

现在,问题的根源在于我似乎无法使用 Makegood 从 Eclipse 运行 PHPUnit 测试。我编写的唯一测试(位于名为“test.php”的“/path/to/application/tests/”文件夹中)如下所示(直接取自 PHPUnit Manual ):
<?php
class StackTest extends PHPUnit_Framework_TestCase
{
public function testPushAndPop()
{
$stack = array();
$this->assertEquals(0, count($stack));

array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));

$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
}
}
?>

为了运行测试,我右键单击“tests”文件夹并在 Eclipse 中点击“Run All Tests”,这会打印到控制台:

PHPUnit 3.7.15 by Sebastian Bergmann.

Configuration read from /path/to/application/config.xml

Time: 0 seconds, Memory: 5.00Mb

No tests executed!



现在,当我尝试使用“path/to/application/tests/”目录中的“phpunit test.php”命令从命令行运行这些测试时,我得到以下控制台输出:

PHPUnit 3.7.15 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 3.25Mb

OK (1 test, 5 assertions)



很明显,我没有正确地告诉 Makegood 在哪里可以找到测试文件/如何运行测试,但我似乎无法确定如何解决这个问题。毫无疑问,对于所有 PHPUnit 组件如何在 Eclipse 中组合在一起,我有一个糟糕的心智模型,因此任何有助于我理解架构的帮助将不胜感激。提前致谢!

最佳答案

“运行所有测试”无法按照您尝试使用的方式工作。 “运行所有测试”运行您选择作为“测试文件夹”之一的测试(见下文)

enter image description here

我实际上将我的测试文件夹更改为此

enter image description here

它只运行 RuleData 文件夹中的测试。你可以点击任何你喜欢的地方,“运行所有测试”就会以这种方式运行。如果您只想运行文件夹中的测试,只需选择“运行测试”

另外这是我的 phpunit xml 配置,它位于测试目录中。

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupStaticAttributes="false"
backupGlobals="false"
bootstrap="./../application/third_party/CIUnit/bootstrap_phpunit.php"
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"

processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"

strict="false"
verbose="true"

>
<php>
<ini name="memory_limit" value="2047M" />
</php>

<testsuites>
<testsuite name="AllTests">
<directory>.</directory>
</testsuite>
</testsuites>

<filter>
<blacklist>
<directory suffix=".php">./../../</directory>
<file></file>
<exclude>
<file></file>
</exclude>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./../application/models</directory>
<directory suffix=".php">./../application/controllers</directory>
<directory suffix=".php">./../application/libraries</directory>
<directory suffix=".php">./../application/helpers</directory>
<file></file>
<exclude>
<directory suffix="index.php">./../application</directory>
<file></file>
</exclude>
</whitelist>
</filter>
</phpunit>

关于PHPUnit Eclipse 配置 : No Tests Found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15188848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com