keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

Create a new GMockController instance before each test in TestNG with @WithGMock #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by julien.g...@gmail.com on 24 Nov 2009 at 7:43

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 20 Dec 2011 at 5:34

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 20 Dec 2011 at 7:39