views:

64

answers:

1

I have unit test case where I am using JMockit with expectations. Now when I run the test case alone, the test case passes. But when I run all test cases collectively, I get the:

expected exactly 1 time, already invoked...

error. I feel that some configuration or states set in jmock by previous test cases has not cleared.

Has anyone experienced something similar?

Thanks

+2  A: 

It sounds to me as if you have defined the allowed number of invocations of a method on a mocked class. Do you have something resembling:

@Mock( invocations = 1 )
{signature for method here}

?

If this is the case, you need to tear down the mock instance using the JUnit @After idiom, in which you'll to tearDownMocks() in order to reset the mock instances used in each test case.

Steen