Ask Your Question
4

What is the process to make a Groovy Spock test compare invocation parameters using equals instead of ==?

asked 2021-10-09 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-05-25 18:00:00 +0000

david gravatar image

To make a Groovy Spock test compare invocation parameters using equals instead of ==, you can use the .equals() method instead of the == operator when specifying the expected invocation parameters. Here is an example code snippet:

def "Test some method with expected parameters"() {
    given:
    def objectUnderTest = new ObjectUnderTest()

    when:
    def result = objectUnderTest.someMethod("param1", "param2")

    then:
    1 * objectUnderTest.someMethod("param1".equals(_), "param2".equals(_)) >> "expectedResult"
}

In this example, the _ symbol is used as a wildcard for any value passed in as an argument to the someMethod method. The .equals() method is then called on the expected parameters to perform the comparison using the equals method instead of the == operator.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-09 11:00:00 +0000

Seen: 8 times

Last updated: May 25 '22