一些示例代码,例如: (我刚刚添加了更多详细信息)
public class A {
@Autowired
private Data data;
@RequestMapping(value="/Boo", method = RequestMethod.GET)
public void Boo(){
data.someMethod();
}
}
我想测试someMethod()是否运行。
我尝试了@First答案,但收到了如下错误消息:
java.lang.AbstractMethodError: org.powermock.api.mockito.internal.exceptions.StackTraceCleanerProvider$1.isIn(Ljava/lang/StackTraceElement;)Z
at org.mockito.internal.exceptions.stacktrace.StackTraceFilter.filter(StackTraceFilter.java:33)
at org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter.filter(ConditionalStackTraceFilter.java:23)
at org.mockito.exceptions.base.MockitoException.filterStackTrace(MockitoException.java:44)
答案 0 :(得分:0)
@RunWith(MockitoJUnitRunner.class)
public class ATest {
@InjectMocks
private A a;
@Spy
private Data data;
@Test
public void test() {
// execute
this.a.Boo();
// verify
Mockito.verify(this.data).someMethod();
}
}