Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

maven - Mock适用于本地,但不适用于Maven(Mock works on local but does not work by maven)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...