2012-04-12 92 views
2

我有一个包含单元测试的php项目。我使用Netbeans进行开发,并希望将phpunit集成到我的IDE中。如果我从命令行运行phpunit,它正在工作。 如果我按Alt + F6运行Netbeans中没有测试运行测试,我得到的消息:(发生也许是一个错误,验证输出窗口)Netbeans“没有执行测试”

测试未执行

的结构(它是一个Zend框架2模块):BarTest.php

namespace Foo; 

use PHPUnit_Framework_TestCase as TestCase; 

class BarTest extends TestCase 
{ 
    public function testIsWorking() 
    { 
     $this->assertTrue(true); 
    } 
} 

Foo/ 
    src/ 
    Foo/ 
     Bar.php 
     Baz.php 
    tests/ 
    Foo/ 
     BarTest.php 
    bootstrap.php 
    phpunit.xml 
    Module.php 
    autoload_register.php 

内容

我phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit bootstrap="bootstrap.php"> 
    <testsuite name="Foo"> 
     <directory>./</directory> 
    </testsuite> 
</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项目属性:

  1. 要设置测试目录Foo/tests(此是必需的我认为)
  2. 专门设置引导文件(不需要我瘦K)
  3. 要专门设置的XML配置文件(不需要我认为)
  4. 要设置专门运行所有*测试文件(不是必需的,我认为)

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

+0

你试过运行'phpunit --bootstrap bootstrap.php Foo/tests'吗?因为多数民众赞成什么IDE最终做 – 2012-04-12 15:12:09

回答

0

尽管我已将error_reporting设置为高级别,但PHP CLI并未打开display_errors。这就是它,所以现在我得到了我的报告...

+0

你能解释这是什么意思,我该怎么做?我也正在'也许发生了一个错误,在输出窗口验证错误。我对PHPUnitTest完全陌生。 – Geek 2013-07-17 10:36:00

+0

bootstrap.php文件包含'error_reporting(E_ALL | E_STRICT);'但不包含'ini_set('display_errors','1');'。所以虽然报告了错误,但并未显示。设置这也显示了我的错误。 – 2013-07-17 10:57:41

+0

感谢您的回复。你能告诉我在哪里可以找到这个bootstrap.php文件吗?我在搜索结果中找到了很多bootstrap.php文件,不知道应该更改哪一个。 – Geek 2013-07-17 11:01:28

0

问题是Netbeans期望位于一个根项目文件夹中的所有测试。如果没有这样做,Code Coverage和其他功能无法正常工作。 有关更多信息,请参见enhancement

这个问题是可以解决的创建自定义的测试套件:

  • 创建根项目文件夹目录“测试”或“测试”,如果它尚未创建。
  • 在此“测试”文件夹中创建文件TestSuite.php
  • 将此TestSuite.php添加到您的Netbeans项目设置中。
<?php 

class TestSuite extends PHPUnit_Framework_TestSuite 
{ 
    public static function suite() 
    { 
     $suite = new TestSuite(); 

     $file = '/Foo/tests/Foo/BarTest.php'; 

     echo 'Adding test: ' . $file . "\n"; 
     $suite->addTestFile($file); 

     //add here algorithm that will search and add all test files from your /tests directory 

    return $suite; 

} 

的Netbeans 7.2将有很好的功能run all test in separate directory

3

你可以简单地把所有这些放到你的PHPUnit引导程序中。php:

<?php 

error_reporting(E_ALL | E_STRICT); 
ini_set('display_errors', '1'); 
ini_set('display_startup_errors', '1'); 
0

NetBeans未找到自动装载机类。然后,在项目设置中,你必须说什么类的自动加载器,引导程序等。

在我的情况刚刚进入:项目属性 - >测试 - > PHPUnit。 我将选项设置为“使用引导程序”,并告诉引导路径。

我的引导文件具有自动加载器,然后我的所有测试类都被执行而没有错误。