Skip to content

FAQ entry: Why we don't support multiple chained calls to assertion methods on the same Subject #884

Open
@timurt

Description

Hi

I have the following assertions:

        String str = ...;
        assertWithMessage(errorMessage)
                .that(str)
                .startsWith("some prefix");
        assertWithMessage(errorMessage)
                .that(str)
                .contains("some content");
        assertWithMessage(errorMessage)
                .that(str)
                .endsWith("some suffix");

As you can see I make several assertions over one str object
It would be easier to understand if all assertions were combined together like:

        assertWithMessage(errorMessage)
                .that(str)
                .startsWith("some prefix")
                .contains("some content")
                .endsWith("some suffix");

I know there are several ways how to overcome it (assign assertWithMessage(errorMessage).that(str) to variable and call assertions for it or by using regular expressions), but sequential invocation of assert methods over one object seems more natural to me


Please guide me, if such functionality already exists

Activity

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

Metadata

Assignees

No one assigned

    Labels

    P3not scheduledtype=documentationDocumentation that is other than for an API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions