I can’t understand how I can setup a parametrized test with spock for void methods.
This is my simple test case for a linked list:
@Unroll
def "should delete the element #key and set the list size to #listSize"(key, listSize) {
given:
list.insert(6)
list.insert(12)
list.insert(33)
expect:
def deletedKey = list.delete(key)
list.size() == listSize
where:
key || listSize
6 || 2
12 || 2
33 || 2
99 || 3
}
The method delete() is a void method, but if I’m not getting explicitly a return value then the test is failing.
This is actually working:
expect:
def deletedKey = list.delete(key)
list.size() == listSize
while this doesn’t:
expect:
list.delete(key)
list.size() == listSize
The test report complains about a null
Condition not satisfied:
list.delete(key)
| | |
| null 12
com.github.carlomicieli.dst.LinkedList@5c533a2
How can I manage this situation? I would like to test the results of deletion checking the list state after the deletion method has been called.
Thanks,
Carlo
Does it work if you use
whenandthenrather thanexpect?