PHPUnit live log on failure / error

I recently ran several thousand phpunit tests. I use the --process-isolation option, so it takes about 40 minutes to complete the tests.

Sometimes after aggressive refactoring, many tests begin to fail (thank God I have tests!). And if the test fails in the middle of the test suite, I have to wait another 20 minutes to find out what the test is and its message.

I would use --stop-on-failure if I didn't interrupt the whole process. I am mainly looking for the option --log-on-failure .

What I'm looking for exactly is a way to see a test error / error message right after its failure, and not after all other tests are complete. But the whole process of performing other tests should not be interrupted. Access to the file will also be sufficient.

I would be grateful for your suggestions.

EDIT: I am glad to see your suggestions, how I could improve my testing in general, and I will try to follow them, however I would like to find a solution to my exact problem.

+4
source share
2 answers

Even if you ignore it, you are looking for --stop-on-failure .

Because when you see where the error is, you can write a correction. Then you need to run the tests again.

If you are just logging into the system, you still cannot run the tests again, because after 10 seconds the first error will be visible and corrected within one more minute. However, you still need to wait for ca. 38 minutes until you can complete the tests.

Another problem is that your tests are too long. You need to get them faster. The fact that you use --process-isolation , after all, a sign that you have integration tests. Separate them from your unit tests, they often take more time.

Then you can run integration tests in isolation and continuously (in a loop, always), and you run unit tests while saving your files.

+2
source

good for you to write all these tests. As you say, they can quickly prove their worth when you start a lot of refactoring! But 40 minutes sounds like a very slow test suite, even for a few thousand of them - several hundred work for me in about 10 seconds. Perhaps you have some tests that are especially slow?

If your system approaches this, it may be worth splitting them into groups so that you can only configure the launch of tests that are relevant to the changing code. PHPUnit supports grouping tests and indicating on the command line which groups to run.

This can be a particularly effective strategy if most of your tests are pretty fast, but you have some very slow tests that take up most of the time. If you can make him skip a few very slow tests when they are not relevant, this will go a long way.

In addition, this test grouping strategy also allows you to use --stop-on-failure for each group, while still having the ability to run all tests in other groups.

For more information on group testing, see the PHPUnit manual .

Hope this helps.

+1
source

All Articles