mardi 4 août 2015

Intertest dependencies with Mockito in Groovy/Spock

I've got a weird issue I can't seem to get around.

Two test cases using the same Mockito mock() in Spock are affecting each other (yes, I know somebody's gonna say I should use Spock's mocking, but I'm not, OK?)

So, the first case is:

when(mock.method(1234)).thenReturn([:]).thenReturn([SOMETHING:1])

the second is:

when(mock.method(1234)).thenReturn([SOMETHING:1])

When I call both test cases, the first one passes and the second one fails. When I just run the second, it succeeds.

My assumption is that I'm constructing a new mock for each test case, but in case that's not true in Spock, I recreated the mock for the first test, and the second still failed. I also tried using a different dummy id in the first test, but it still had an effect on the second test.

Any help is appreciated!

Aucun commentaire:

Enregistrer un commentaire