这在InitializationError中失败了。同一包中的其他测试运行,所以我在代码中做了一些愚蠢的事情。Stacktrace读到“没有找到匹配的测试[精确匹配]”。
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));
}
}什么都试过了,但对莫基托来说还是很新的。我在这里做什么傻事?
谢谢
发布于 2016-07-25 11:54:01
我发现有两件事需要修复:
@Test方法应该没有参数File实例,名为fileMock。下面是更新的代码:
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));
}
}https://stackoverflow.com/questions/38484514
复制相似问题