Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “Netbeans”;“未执行任何测试”;_Php_Unit Testing_Netbeans_Phpunit - Fatal编程技术网

Php “Netbeans”;“未执行任何测试”;

Php “Netbeans”;“未执行任何测试”;,php,unit-testing,netbeans,phpunit,Php,Unit Testing,Netbeans,Phpunit,我有一个包含单元测试的php项目。我使用Netbeans进行开发,并希望在我的IDE中集成phpunit。如果我从命令行运行phpunit,它就工作了如果我按Alt+F6在Netbeans中运行测试,则无测试运行,我会收到以下消息: 未执行任何测试(可能发生错误,请在输出窗口中验证。) 结构(它是Zend Framework 2模块): BarTest.php的内容 namespace Foo; use PHPUnit_Framework_TestCase as TestCase; clas

我有一个包含单元测试的php项目。我使用Netbeans进行开发,并希望在我的IDE中集成phpunit。如果我从命令行运行phpunit,它就工作了如果我按Alt+F6在Netbeans中运行测试,则无测试运行,我会收到以下消息:

未执行任何测试(可能发生错误,请在输出窗口中验证。)

结构(它是Zend Framework 2模块):

BarTest.php的内容

namespace Foo;

use PHPUnit_Framework_TestCase as TestCase;

class BarTest extends TestCase
{
    public function testIsWorking ()
    {
        $this->assertTrue(true);
    }
}
My phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="bootstrap.php">
    <testsuite name="Foo">
        <directory>./</directory>
    </testsuite>
</phpunit>
在Netbeans项目属性中,我尝试了:

  • 将tests目录设置为
    Foo/tests
    (我认为这是必需的)
  • 专门设置引导文件(我认为不是必需的)
  • 专门设置XML配置文件(我认为不是必需的)
  • 专门设置为运行所有*测试文件(我认为不是必需的)

  • 如何确保Netbeans可以执行phpunit测试?

    问题是Netbeans希望所有测试都位于一个根项目文件夹中。如果不这样做,代码覆盖率和其他特性将无法正常工作。 有关更多信息,请参阅

    创建自定义测试套件可以解决此问题:

    • 在根项目文件夹中创建目录“test”或“tests”(如果尚未创建)
    • 在这个“test”文件夹中创建文件TestSuite.php
    • 在Netbeans项目设置中添加这个TestSuite.php

    虽然我已将错误报告设置为高级别,但PHP CLI没有启用显示错误。就是这样,现在我得到了我的报告…

    您只需将所有这些内容放到PHPUnit bootstrap.php中即可:

    // Set error reporting pretty high
    error_reporting(E_ALL | E_STRICT);
    
    // Get base, application and tests path
    define('BASE_PATH',  dirname(__DIR__));
    
    // Load autoloader
    require_once BASE_PATH . '/autoload_register.php';
    

    NetBeans找不到自动加载程序类。然后,在项目设置中,您必须说明类autoloader、bootstrap等的内容

    在我的例子中,只是进入:项目属性->测试->PHPUnit。 我将选项设置为“使用引导”,并告知引导的路径


    我的引导文件有自动加载程序,然后我的所有测试类都没有错误地执行。

    您是否尝试运行
    phpunit--bootstrap bootstrap.php Foo/tests
    ?因为IDE最终就是这么做的。你能解释一下这意味着什么,我该怎么做吗?我还收到
    可能发生错误,请在输出窗口中验证。
    错误。我对phpunitest完全陌生。bootstrap.php文件包括
    错误报告(E|u ALL | E|u STRICT)但不是
    ini\u集('display\u errors','1')。因此,尽管报告了错误,但没有显示它们。设置这个也显示了错误。感谢您的回复。你能告诉我在哪里可以找到这个bootstrap.php文件吗?我在搜索结果中得到了这么多bootstrap.php文件,不知道应该更改哪一个。
    
    // Set error reporting pretty high
    error_reporting(E_ALL | E_STRICT);
    
    // Get base, application and tests path
    define('BASE_PATH',  dirname(__DIR__));
    
    // Load autoloader
    require_once BASE_PATH . '/autoload_register.php';