PHPUnit TDD, PHP Fatal error: method call undefined

I'm starting a TDD project using PHPUnit, and something really scares me.

It seems that all tests cannot be executed until all classes and methods are implemented. How to make the test continue the event if the class or method is not yet implemented?

Thanks.

Edit: "Isn't it TDD that your testuite fails while writing tests?" Yes, of course, but I want to have a global view of the project. Let's say we wrote 1000 tests, and the first one that runs leads to a fatal error. But we were not lucky when we started to implement the code, this part will be one of the last to be implemented. I do not want to develop “blinds” and only have the ability to run my test sets when all the fatal error is cleared.

So yes, their huge difference is between a test that fails and the whole testing process to stop / die due to a fatal error, which is normal in this state.

As a work-arround, we created our class skeleton before starting to write our tests.

+2
source share
1 answer

Is it not TDD that your testuite fails to write tests?

I assume your thought is that he is dying with a fatal error, and not just showing the red line "i failed". A very interesting point, I am doing TDD with phpunit, but it never listened to me at all.

The first thing that came to mind was --process-isolation .

Example:

Suppose a test class looks like this:

 <?php class fooTest extends PHPUnit_Framework_TestCase { public function testA() { $x = new a(); } public function testB() { $this->assertTrue(true); } } 

using a regular phpunit test.php runner:

 PHPUnit 3.5.12 by Sebastian Bergmann. Fatal error: Class 'a' not found in /home/mcsvnls/mep.php on line 6 

but when using the phpunit --process-isolation test.php switch, it looks like this:

 PHPUnit 3.5.12 by Sebastian Bergmann. E. Time: 1 second, Memory: 3.25Mb There was 1 error: 1) fooTest::testA RuntimeException: Fatal error: Class 'a' not found in /home/foo/mep.php on line 6 Call Stack: 0.0005 102364 1. {main}() /home/foo/-:0 0.0341 1768644 2. __phpunit_run_isolated_test() /home/foo/-:143 [...........] FAILURES! Tests: 2, Assertions: 1, Errors: 1. 

And now the second test runs and passes

+5
source

Source: https://habr.com/ru/post/912774/


All Articles