Because TestNG doesn't create new instances of test classes for each test,
the GMockController instance which is injected via the @WithGMock
annotation will be the same for each test. It makes the default mock names
strange: the mock name in the first test will be "Mock for Object", and the
second test "Mock for Object (2)", and the third test "Mock for Object
(3)", ..., that is, it makes the following test failed:
@Test(invocationCount = 3) void mockName() {
def mock = mock()
assertEquals 'Mock for Object', JavaTestHelper.toStringOn(mock)
}
Solution: if we can find the org.testng.annotations.BeforeMethod class,
then we find the method with @BeforeMethod annotation in the test class
(inject one if none is found), insert the "$gmockController = new
GMockController()" statement to the front of the method.
Original issue reported on code.google.com by JohnnyJianHY on 19 Oct 2009 at 2:05
Original issue reported on code.google.com by
JohnnyJianHY
on 19 Oct 2009 at 2:05