Skip to content

Tested Expected Exceptions #27

Description

@grantjforrester

I wondered if you'd seen: https://github.com/Codearte/catch-exception

I particularly like the fluent style for asserting features of the thrown exception. (from the README) ..

// given: an empty list
List myList = new ArrayList();

// when: we try to get the first element of the list
when(myList).get(1);

// then: we expect an IndexOutOfBoundsException
then(caughtException())
        .isInstanceOf(IndexOutOfBoundsException.class)
        .hasMessage("Index: 1, Size: 0")
        .hasNoCause();

I always recommend some testing of the message to ensure your failing for the right reason. I've seen countless examples where the exception type was valid but the reason was not what was expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions