Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug some PhpUnit tests in Eclipse

I use Eclipse PDT for PHP. I can run my PhpUnit tests : works fine.

But I can not debug my unit tests. Has someby already done this ? Can somebody help doing this ?

Thanx, Messaoud

like image 209
Messaoud Avatar asked Oct 28 '09 14:10

Messaoud


People also ask

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. PHPUnit. Developer(s)

Is PHPUnit a framework?

PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. The currently supported versions are PHPUnit 9 and PHPUnit 8.


1 Answers

An example is more worth than 1000 words :

require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';

class MyTestCase extends PHPUnit_Framework_TestCase {

 protected function setUp() {
  parent::setUp ();

 }

 function testSimple() {
  echo "horray !";
 }

 protected function tearDown() {

  parent::tearDown();
 }

 static function main() {

  $suite = new PHPUnit_Framework_TestSuite( __CLASS__);
  PHPUnit_TextUI_TestRunner::run( $suite);
 }
}

if (!defined('PHPUnit_MAIN_METHOD')) {
    MyTestCase::main();
}

the key thing is :

  1. provide a main method in your testcase

  2. test if the test is executed directly (via php MyTestCase.php) or by phpunit itself. if executed directly - just start the testrunner.

know you can debug your testcase.

like image 132
2 revs, 2 users 74% Avatar answered Oct 07 '22 00:10

2 revs, 2 users 74%