PHPUnit Empty test?
I have a simple setup for a unit test but I am always getting an error that the test suite is empty. I have:
<?php
require_once '../scripts/init_core.php';
class TandyUnitTest extends PHPUnit_Framework_TestCase {
/**
* @group shipping
*/
public function ShippingCharge() {
$ship_options = Model::init('ship_options');
var_dump($ship_options);
}
}
WIth the attached PHPUnit settings. Why isn't the function 'ShippingCharge not getting executed?
Thank you.
Kevin
Attachment(s):
phpunitsettings.jpg
Please sign in to leave a comment.
Hi there,
PHPUnit needs to know what methods are tests and what are other/normal methods (helpers). For that -- http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html
1) Individual tests (methods) should start with test as part of the name (i.e. testShippingCharge)
2) or have @test in their PHPDoc comment
Another common convention is to have file names with tests to be ended with Test (i.e. MySpecialClassTest.php)
I changed the declaration like:
class TandyUnitTest extends PHPUnit_Framework_TestCase {
/**
* @test
* @group shipping
*/
public function testShippingCharge() {
$ship_options = Model::init('ship_options');
var_dump($ship_options);
}
}
And I still don't see the testShippingCharge method executing and I see a message at the bottom of the IDE indicating that there is an "Empty test suite". Also there is a red message on the left hand pane of the IDE indicating the "Test framework quit unexpectedly".
Thank you.
Sorry -- not enough info. Therefore: screenshots please (of whole IDE where all details are shown).
Even better:
I am working on getting a "simple project" working. In the mean time I have attached the applicable screenshots.
Attachment(s):
UnitTest2.jpg
UnitTest1.jpg
This simple project shows the same symptoms.
Attachment(s):
BasicUnitTest.zip
1) Works for me.
I'm using v8 EAP build as your v7.1.3 does NOT support latest PHPUnit versions (PhpStorm v7.1.3 supports 3.7 max; the PHAR files downloadable using that link (from within IDE) are v4.x).
What PHPUnit version do you use there (mine is latest 4.1.3 as seen from screenshot)?
2) Your screenshot -- you are trying to debug (instead of just running) + it is for your real project.
A) Could you use "run" instead of "debug"
B) Could you show the same but for test project please?
I am using 4.1.3. What version should I use?
Same result when I "run" and don't debug. Both in the real project and the test project.
Thank you.
Attachment(s):
UnitTest3.jpg
I tried PHPUnit 3.7.37 and it still didn't work.
. . .
Quoting myself:
Therefore: to use PHPUnit v4.x you need to use PhpStorm v8 EAP build -- PhpStorm EAP
In such case I do not know what may be wrong here.
Definitely check PHP's error log -- ths "Test framework quit unexpectedly" could mean that PHP cannot find/load requested class or similar.
... But then ... it should work on test project where no external dependencies present...
No other ideas, unfortunately.
Where is the idea log?
What would be the command line arguments for PHPUnit.phar?
Thank you.
Help | Show log in...
http://phpunit.de/manual/current/en/installation.html#installation.phar