簡體   English   中英

Mockito.lenient不返回預期結果

[英]Mockito.lenient does not return expected result

@RunWith(MockitoJUnitRunner.class)
public class TestMyStuff{
    @Mock
    private Worker worker;

    @Before
    public void setup(){
        Mockito.lenient()
                .when(worker.doWork("some stuff", "some other stuff", new Date()))
                .thenReturn(true);
        Mockito.lenient()
                .doReturn(true)
                .when(worker).doWork("some stuff", "some other stuff", new Date());
    }

    @Test
    public void test(){
        //quick test to see if mock works.
        final boolean isDone = worker.doWork("zzz", "qwerty);
        System.out.println("isDone: " + isDone);//i want isDone to be true
    }
}

Mockito.lenient()方法似乎不起作用,因為它沒有返回true 無論輸入如何,如何使Worker.#doWork()返回true

您可以使用以下代碼: when(Worker.doWork(anyString(),...).thenReturn(true)但是,我認為您發布的代碼有一些問題,“ doWork”方法似乎需要兩個String和一個Date對象。在測試方法中,應為“ doWork”提供適當的輸入以查看結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM