Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.
This repository was archived by the owner on Apr 12, 2018. It is now read-only.

Testing an exception is not thrown #171

Closed
@xmontero

Description

@xmontero

Here, http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html it says that you can easily test an exception is thrown. But maybe you want to test that an exception is not thrown.

For example, a funcion accepts a number x and must be even. If it is odd raises an InvalidArgumentException.

You might want a a testInvalidArgumentThrowsException with dataprovider [111, 3, 77] as well as testValidArgumentDoesNotThrowException with data provider of [2, 10, 48]

Despite I can test exception with the /** xxx */ comment, I try not thrown via a try/catch.

If there is any way to test "not thrown" I suggest to include in that documentation page. If there is no cleaner way, I also suggest to include it in that documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions