Skip to content

Making expected SQL annotations more descriptive and repeatable #222

Closed
@nagyesta

Description

@nagyesta

Description
First of all, let me say this is a very useful library, great job!

I think it would be even better if the SQL annotations allowed us to add a comment to clarify why we are expecting to have that amount of queries. Plus it would be even better if they would be repeatable.

This would be great for those of us who are running a tight ship and want to clarify why we would expect exactly 42 selects to be executed in a test method. Currently the only option to do so is with comments, but those are not enforced and can become outdated.

If an annotation is repeated, their values should be summed up and then the sum should be compared with the actual detected select count.

Implementation ideas
I would like to do something like this:

    @Test
    @ExpectInsert(value = 3, comment = "Insert 3 users")
    @ExpectInsert(value = 10, comment = "Insert 10 comments")
    @ExpectInsert(value = 10, comment = "Insert 10 posts")
    @ExpectUpdate(value = 3, comment = "Update users")
    @ExpectSelect(value = 1, comment = "Load the user details")
    @ExpectSelect(value = 2, comment = "Load latest comments/posts")
    @ExpectSelect(value = 3, comment = "Load friend list and their latest comments/posts")
    @ExpectDelete(value = 3, comment = "Delete comments, users, posts")
    void test() {
        //...
    }

or alternatively

    @Test
    @ExpectInserts({
        @ExpectInsert(value = 3, comment = "Insert 3 users"),
        @ExpectInsert(value = 10, comment = "Insert 10 comments"),
        @ExpectInsert(value = 10, comment = "Insert 10 posts")
    })
    @ExpectUpdate(value = 3, comment = "Update users")
    @ExpectSelects({
        @ExpectSelect(value = 1, comment = "Load the user details"),
        @ExpectSelect(value = 2, comment = "Load latest comments/posts"),
        @ExpectSelect(value = 3, comment = "Load friend list and their latest comments/posts")
    })
    @ExpectDelete(value = 3, comment = "Delete comments, users, posts")
    void test() {
        //...
    }

If we provided 1 wrapper for each of the ExpectSelect, ExpectInsert, ExpectUpdate, ExpectDelete annotations, then it would be very flexible.

What do you think?

I would be happy to implement these changes if you like the idea...

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions