Mockito stubbing outside of the test method

后端 未结 1 1903
旧时难觅i
旧时难觅i 2021-02-09 05:24

I have the following method outside the test method

private DynamicBuild getSkippedBuild() {
    DynamicBuild build = mock(DynamicBuild.class);
    when(build.i         


        
1条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-09 05:56

    If isSkipped() is not a final method, this problem probably indicates that you try to stub a method while stubbing of another method is in progress. It's not supported because Mockito relies on order of method invocations (when(), etc) in its stubbing API.

    I guess you have something like this in your test method:

    when(...).thenReturn(getSkippedBuild());
    

    If so, you need to rewrite it as follows:

    DynamicBuild build = getSkippedBuild();
    when(...).thenReturn(build);
    

    0 讨论(0)
提交回复
热议问题