To kill some PIT mutants, I added a Spy that verifies some condition and then uses callRealMethod() in a setup() method.
In some tests I also added a Spy on the same object that also calls callRealMethod().
so in the end it was like
testee.field = Spy(testee.field)
testee.field.someMethod() >> {
// verify some condition here
callRealMethod()
}
testee.field = Spy(testee.field)
testee.field.someMethod() >> {
// verify some other condition here
callRealMethod()
}
Now if testee.field.someMethod() is called I would have expected that the second spy tests "some other condition", then delegates to the first spy which tests "some condition" and then delegates to the real method.
Unfortunately, the first spy was skipped and after testing "some other condition" the second spy delegated to the real method directly.
This causes the mutant to not be killed properly (or rather a timeout due to a deadlock which costs more time than would have been necessary).
I worked around it by instead using a helper method that gets a closure, but it would be nice if it would actually work like expected. The workaround looks something like:
def prepareLocks(Closure someMethodInterceptor = { callRealMethod() }) {
testee.field = Spy(testee.field)
testee.field.someMethod() >> {
// verify some condition here
someMethodInterceptor.tap { it.delegate = owner.delegate }.call()
}
}
def test() {
given:
prepareLocks {
// verify some other condition here
callRealMethod()
}
// other test content
}
To kill some PIT mutants, I added a Spy that verifies some condition and then uses
callRealMethod()in asetup()method.In some tests I also added a
Spyon the same object that also callscallRealMethod().so in the end it was like
Now if
testee.field.someMethod()is called I would have expected that the second spy tests "some other condition", then delegates to the first spy which tests "some condition" and then delegates to the real method.Unfortunately, the first spy was skipped and after testing "some other condition" the second spy delegated to the real method directly.
This causes the mutant to not be killed properly (or rather a timeout due to a deadlock which costs more time than would have been necessary).
I worked around it by instead using a helper method that gets a closure, but it would be nice if it would actually work like expected. The workaround looks something like: