Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spying on Spys does not work properly #1029

Open
Vampire opened this issue Sep 17, 2019 · 0 comments

Comments

@Vampire
Copy link
Contributor

commented Sep 17, 2019

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.