Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run all my PHPUnit tests?

I have script called Script.php and tests for it in Tests/Script.php, but when I run phpunit Tests it does not execute any tests in my test file. How do I run all my tests with phpunit?

PHPUnit 3.3.17, PHP 5.2.6-3ubuntu4.2, latest Ubuntu

Output:

$ phpunit Tests PHPUnit 3.3.17 by Sebastian Bergmann. Time: 0 seconds OK (0 tests, 0 assertions) 

And here are my script and test files:

Script.php

<?php   function returnsTrue() {       return TRUE;   }   ?> 

Tests/Script.php

<?php   require_once 'PHPUnit/Framework.php';   require_once 'Script.php'    class TestingOne extends PHPUnit_Framework_TestCase   {      public function testTrue()     {         $this->assertEquals(TRUE, returnsTrue());     }      public function testFalse()     {         $this->assertEquals(FALSE, returnsTrue());     } }  class TestingTwo extends PHPUnit_Framework_TestCase   {      public function testTrue()       {           $this->assertEquals(TRUE, returnsTrue());       }      public function testFalse()     {         $this->assertEquals(FALSE, returnsTrue());     } }   ?> 
like image 632
JJ. Avatar asked Sep 12 '09 02:09

JJ.


People also ask

How do I run a test case in PHP?

In the PHP Explorer, right-click the file, and select New | PHPUnit Test Case. The New PHPUnit Test Case dialog is displayed. To select the element to be tested, click Browse next to the Tested Element field. The Element selection dialog is displayed.

What is PHPUnit testing?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.

How do you run a unit test?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).


2 Answers

Php test's filename must end with Test.php

phpunit mydir will run all scripts named xxxxTest.php in directory mydir

(looks likes it's not described in the phpunit documentation)

like image 122
Mabrouk Avatar answered Sep 29 '22 01:09

Mabrouk


I created following phpunit.xml and now atleast I can do phpunit --configuration phpunit.xml in my root directory to run the tests located in Tests/

<phpunit backupGlobals="false"          backupStaticAttributes="false"          syntaxCheck="false">   <testsuites>     <testsuite name="Tests">       <directory suffix=".php">Tests</directory>     </testsuite>   </testsuites> </phpunit> 
like image 24
JJ. Avatar answered Sep 28 '22 23:09

JJ.