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?
To run the unit test, click the arrow next to the Run button on the Tool-bar, and select Run As | PHPUnit Test . From the Menu-bar, select Run | Run As | PHPUnit Test . To debug the PHPUnit Test Case, click the arrow next to the debug button on the toolbar, and select Debug As | PHPUnit Test .
Installing PHPunit on Windows Installing PHPunit basically requires downloading one single . phar file, which can be executed with PHP. You can find it on the PHPunit Getting Started section of their page, or simply save the following link: https://phar.phpunit.de/phpunit.phar.
PHPUnit is used for unit testing your PHP projects. The word Unit refers to a block of code, method or an individual or independent class. Unit testing is a software testing process in which code blocks are checked to see whether the produced result matches the expectations.
You can integrate add-on for running unit tests via native web GUI:
https://github.com/NSinopoli/VisualPHPUnit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With