Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit runs only from the command line. Why?

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?

like image 921
Gabriel Avatar asked May 19 '11 21:05

Gabriel


People also ask

How do I run a PHPUnit test?

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 .

How do I run PHPUnit on Windows?

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.

Why do we use PHPUnit?

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.


1 Answers

You can integrate add-on for running unit tests via native web GUI:

https://github.com/NSinopoli/VisualPHPUnit

like image 124
lubosdz Avatar answered Oct 23 '22 03:10

lubosdz