This fails with InitializationError. Other tests in the same package run so I have done something silly in my code. Stacktrace reads "No tests found matching [[Exactmatch]]".
public class TestClassToTest {
@Mock
File mockOfAFile;
@Test
public void testAMethod(File mockOfAFile) {
MockitoAnnotations.initMocks(this);
given(fileMock.getName()).willReturn("test1");
assertEquals("test1",ClassBeingTested.methodBeingTested(mockOfAFile));
}
}
Have tried everything but am very new to Mockito. What silly thing am I doing here ?
Thanks
I found two things to fix:
@Test
method should have no parameters File
instance, called fileMock
. So here is the updated code:
public class TestClassToTest {
@Mock
File mockOfAFile;
@Mock
File fileMock; // the new mock
@Test
public void testAMethod() { // no parameters
MockitoAnnotations.initMocks(this);
given(fileMock.getName()).willReturn("test1"); // here is the new mock used
assertEquals("test1",ClassBeingTested.methodBeingTested(mockOfAFile));
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.