I have a problem in a unit test with mockito.
(我在使用Mockito进行单元测试时遇到问题。)
I am running test by the idea and everything is fine. (我正在通过这个想法进行测试,一切都很好。)
But when I run it by maven, it does not mock the object and it goes to real method and this cause failure of test. (但是当我由maven运行它时,它不会模拟该对象,而是转到实际方法中,这会导致测试失败。)
But how this can happen and mock works when I run test by Intellij but when I run it by maven it does not work? (但是,这种情况发生和模拟的作品时,我的IntelliJ由运行测试,但是当我通过运行Maven的它不工作?)
Code is pretty simple:
(代码很简单:)
@MockBean
private MyObj myobj;
@Test
public void myTest() throws Exception{
.....
when(myobj.myMethod(defaultVal, "XX"))
.thenReturn("XX");
}
public interface MyObj{
String myMethod(final String val, final String val2);
}
ask by user1474111 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…