Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PHPUnit fail on risky tests

I want PHPUnit to fail if one or more test is considered as risky. Actually:

PHPUnit 5.3.4 by Sebastian Bergmann and contributors.

..RRR..                                                         7 / 7 (100%)

Time: 2.83 seconds, Memory: 26.00Mb

OK, but incomplete, skipped, or risky tests!
Tests: 7, Assertions: 137, Risky: 3.

It says "OK, but incomplete", so my tests did not fail (and can be shipped in case of continous delivery). Is there any way to have a "fail" status? I want my test global status considered as failed on risky test, don't know if it's possible.

like image 876
rap-2-h Avatar asked Jul 11 '16 09:07

rap-2-h


People also ask

Which method is used to create a mock with PHPUnit?

PHPUnit provides methods that are used to automatically create objects that will replace the original object in our test. createMock($type) and getMockBuilder($type) methods are used to create mock object. The createMock method immediately returns a mock object of the specified type.

What is a PHPUnit test?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit design for unit testing systems that began with SUnit and became popular with JUnit. Even a small software development project usually takes hours of hard work.

How do I run a PHPUnit test case?

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 . From the Main Menu, select Run | Debug As | PHPUnit Test .


1 Answers

You can use the --fail-on-risky flag when calling the PHPUnit executable, or set the failOnRisky="true" attribute to the <phpunit> element in phpunit.xml.

In contrary to --stop-on-risky/stopOnRisky="true" this will not stop the test suite when PHPUnit encounters a risky test, but it will make PHPUnit exit with a non-zero status code, as it would when one of the tests fails.

like image 113
Nic Wortel Avatar answered Oct 03 '22 13:10

Nic Wortel