简体   繁体   English

Netbeans-PHPUnit“没有执行测试”错误

[英]Netbeans-PHPUnit “No tests executed” error

I am newbie to any kind of testing. 我是任何一种测试的新手。 I just installed pear and PHPUnit using this doc . 我刚刚使用这个doc安装了pear和PHPUnit。 I use netbeans 7.3.1. 我使用netbeans 7.3.1。 I also installed skeletongenerator running this command : pear install phpunit/PHPUnit_SkeletonGenerator . 我还安装了运行此命令的skeletongeneratorpear install phpunit/PHPUnit_SkeletonGenerator

I Followed the steps listed in this testing with PHPUnit to integrate PHPUnit to netbeans. 按照PHPUnit中的测试中列出的步骤将PHPUnit集成到netbeans中。
As described in Installing PHPUnit section of that doc, by clicking search button under Netbeans->preferences->unit testing my netbeans recognizes PHPUnit installation. 如该文档的Installing PHPUnit部分所述,通过单击Netbeans->preferences->unit testing下的search按钮,我的netbeans可识别PHPUnit安装。

I followed all the steps to add sample Calculator project and generate test class. 我按照所有步骤添加示例Calculator项目并生成测试类。 I did that. 我做到了 But when I run the tests by right clicking Calculator.php file and selecting Test I get following result. 但是当我通过右键单击Calculator.php文件并选择Test来运行测试时,我得到以下结果。

在此输入图像描述

Output window shows nothing useful : 输出窗口没有任何用处:

在此输入图像描述

I have no idea of what can be the problem and how to solve that. 我不知道可能是什么问题以及如何解决这个问题。

Few doubts that may be causing the above problem : 很少有人怀疑可能导致上述问题:
What should I add in Global include path under Netbeans->preferences->general ? 我应该在Netbeans->preferences->general下的Global include path添加什么?
Do I need to add require_once statement in Calculator.php file? 我是否需要在Calculator.php文件中添加require_once语句?
Do I need to create php projects under some particular folder only or is it immaterial where I place projects? 我是否只需要在某个特定文件夹下创建php项目,或者我放置项目的位置是不重要的?
How do I check that PHPUnit is installed properly and is working? 如何检查PHPUnit是否已正确安装并且正在运行?

There can be many other symptoms that I am not even able to think of. 还有许多其他症状我甚至无法想到。

Thank you. 谢谢。

Solved by adding below line to Calculatortest.php file. 通过在Calculatortest.php文件中添加以下行来解决。

require_once dirname(__FILE__) . '/../Calculator.php';

The test class is placed in a subdirectory, so I needed to declare the path relative to the Calculator.php. 测试类放在一个子目录中,所以我需要声明相对于Calculator.php的路径。

Also, I had to change php.ini file so that errors are displayed in case there are. 此外,我不得不更改php.ini文件,以便在出现错误时显示错误。
I set following variables in php.ini. 我在php.ini中设置了以下变量。

error_reporting  =  E_ALL | E_STRICT
display_errors = On

I had suffered the same problem. 我遇到了同样的问题。 However, perseverance paid. 但是,坚持不懈。

1) Create the sample project using NB samples. 1)使用NB样本创建示例项目。

2) The directory structure should be: 2)目录结构应该是:

  • Source Files 源文件
    • Calculato.php Calculato.php
  • Test Files 测试文件
  • Include Path 包括路径

3) Right click on Calculator.php and choose Tools > Create Tests 3)右键单击Calculator.php并选择“工具”>“创建测试”

4) Add require_once '../src/Calculator.php'; 4)添加require_once '../src/Calculator.php'; immediately after the top <?php 紧接在顶部<?php

5) Select Calculator.php and select Test 5)选择Calculator.php并选择Test

It worked for me. 它对我有用。 Let me know if it works for you. 请让我知道这对你有没有用。 I hope, your configuration is ok. 我希望,你的配置还可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM