“没有执行测试”我根本无法在NetBeans中运行任何PHP测试

I am very new to NetBeans and I just wanted to run a Code Coverage teston my code developed earlier. I do not know what I am doing wrong.

I am using NetBeans 7.3.1 with Wamp Server 2.4, installed PHPUnit and Skeleton Generator through PEAR, and set those files in NetBeans settings.

I made the project using an existing sources. Running in my browser seems OK. I can even debug with XDebug.

But when I right click on the project name and "Test", it says "No tests executed.(0.0 s)" in the Test Result window, and this in the Output window:

PHPUnit 3.7.23 by Sebastian Bergmann.

Configuration read from C:\wamp\www\test\configuration.xml



Time: 141 ms, Memory: 2.00Mb

No tests executed!

Generating code coverage report in Clover XML format ... done

I tried running test on a PHP file, it returns an information dialog box "Test file for the selected source file was not found."

I right clicked on the PHP file, and selected "Tools->Create PHPUnit tests", it returns a warning dialog box "Tests were not generated for the following files: (file name) Review the log in Output Window." but nothing was changed in the Output window.

I generated PHPUnit Bootstrap and XML Configuration, but they did not help.

I wished I can provide screenshots, but I cannot. I am trying to be specific as possible. I appreciate any help.

PHPUnits message:

No tests executed!

just means that no tests were found. This can have multiple reasons:

First of all, if there are no tests, no tests are executed.

But it is also possible that there are tests, but the configuration says to skip those (for example some tests are grouped into a group named slow and the configuration XML says to exclude slow from being run).

For your case this most certainly is a configuration issue. I'm not fluent with Netbeans but as you can successfully execute PHPUnit already, that part of your setup looks working.

Next step is to find out when you invoke the test-runner where it looks for tests. It might just be that the tests directory is missing or not specified. E.g. check which configuration is in configuration.xml for example and compare that with the documentation to double-check all settings.

This is not a very concrete answer and somebody who is more fluent with Netbeans might help more, however as you'er not showing further screenshots, this is my honest best bet how to go on with trouble-shooting and why.

Seems I am getting closer to the solution. I found out the problem is not in the configurations, but in the code itself.

I do not know if this is a silly problem, but seems the test only accepts PHP codes written in OOP. I tried making another file with a class and I can make test file out of it with no problem. At least I can see the test result changes from "No test executed" to "No test passed, 1 test skipped"

My codes are written for months without OOP and I know nothing about it at all. Does this mean I have to rewrite all of them again?

It will happen when you put an assertion in a constructor of your test class and this assertion fails. Then you will see only the warning 'No tests executed!' (not very helpful) but i suppose one should not put assertions in the constructors (this is in phpunit 4.1~).

I got this error too.. I also got this in the Output tab

Fatal error: Class 'package\path\Tests\TestCase' not found in project\path\package\path\Tests\ClientTest.php on line 25

Here, TestCase is the subclass of PHPUnit_Framework_TestCase and that, along with the current test file is in a different directory structure than the source files. So, in my case, it was a path issue.

Something I noted is I need to add a bootstrap file to include files in the test path and the source path to the runtime.

This bootstrap could be generated by NetBeans. See instructions here: https://netbeans.org/kb/docs/php/phpunit.html#project-specific-configurations

I of course, had another bootstrap.php (added by another developer). I only had to link the bootstrap like follows,

enter image description here

Good luck!

for it was because my test names were not starting with 'test'