I want to pass tests which get the following: “This test did not perform any assertions”
I know I could add something like assertTrue(true) however is it possible to add something to the config to make these tests pass cleaner?
I’m pretty sure this only happens since version PHPUnit 3.5.0 with the introduction of
--strict
Edit: You’ve got a few choices depending on which version you’re using, whether you want to ignore all risky tests or just a few, and if you want it to be permanent or temporary.
Prior to 5.6, if you didn’t want to add bogus assertions to all your tests, you had to avoid passing
--strictto PHPUnit or addstrict="false"to yourphpunit.xml. The point of this option is to "Mark a test as incomplete if no assertions are made."At some point, PHPUnit added the related
--dont-report-useless-testscommand-line switch andbeStrictAboutTestsThatDoNotTestAnything="false"config option. I haven’t checked if they are replacements or additional fine-grained versions.The above options affect all risky tests. Using them will leave you open to accidentally writing tests without assertions. The following new options are safer as you have to purposefully mark each risky test that you wish to allow.
PHPUnit 5.6 added the
@doesNotPerformAssertionsannotation to mark individual test cases as "not risky" even though they perform no assertions.PHPUnit 7.2 introduced
TestCase::expectNotToPerformAssertions()which does the same thing.