问题
I have the following code:
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testCalculate()
{
$this->assertEquals(2, 1 + 1);
}
}
?>
When I open the PHP file in the browser, I get the following error:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found
However, if I use the command line it works fine: phpunit [local_path_here]/testcase.php
Result:
.
Time: 0 seconds, Memory: 5.00Mb
OK (1 test, 1 assertion)
Why is that? How can I make it to run it in the browser as well?
回答1:
You can integrate add-on for running unit tests via native web GUI:
https://github.com/NSinopoli/VisualPHPUnit
回答2:
You can't run unit tests in the browser. Maybe in the future: http://sebastian-bergmann.de/archives/638-PHPUnit-3.0.html#c4983
If you want to view the code coverage run
phpunit --coverage-html=coverage testcase.php
and then open the index.html file in the coverage directory.
Otherwise, you have to run your tests from the command line.
回答3:
You may have a different include path on the command line. Check to see whether you have a php-cli.ini
file in addition to the normal php.ini
file. The first one will be used when you run PHP from the command line. That's probably got a different include_path
setting. It might include the PEAR directory, for example, if PHPUnit was installed via PEAR.
回答4:
You can use eclipse also to run phpunit. follow the link below
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit
来源:https://stackoverflow.com/questions/6064951/phpunit-runs-only-from-the-command-line-why