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.
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
Asked: 2021-10-09 11:00:00 +0000
Seen: 8 times
Last updated: May 25 '22
How to choose specific parameters while selecting inputs in Jenkins (Groovy) Pipeline?
What is the process of serializing groovy traits using Gson?
What is the method to transform an XML hierarchical arrangement to CSV utilizing groovy?
How can Quartz be utilized in Grails?
How to modify the node label in Jenkins once the job has been completed successfully?
What are the typical approaches found in a Gradle build script?
How can a list of objects in Groovy be created from Json?
How to provide the workspace path as a file to setReportDir in XmlTestRunListener using groovy?