簡體   English   中英

Mockito:要測試的類中的空對象

[英]Mockito: null object in class to test

我是junit和mockito的新手,因此問題可能很明顯。 我有一個與嘲諷有關的問題,其中“測試對象”內的本地實例化對象為null。 在此特定部分中沒有私有/受保護/最終方法被調用,所以這不是問題。 我也使用PowerMockito進行其他私有方法調用。

我要測試的類的部分:在user.getId()上引發了空指針異常-此處的最后一行:

SupportProdUpdatesImpl pAdd = new SupportProdUpdatesImpl();       
Add.setQueryProcssStatus(form.getQueryProcssStatus());          

pAdd.setQueryTitle(form.getQueryTitle().toUpperCase());         
pAdd.setQueryType(form.getQueryType().toUpperCase());

logger.debug("*** query String = " + form.getQuerySQL() );
    pAdd.setQuerySQL(StringUtils.trim(form.getQuerySQL()));
    pAdd.setMakerId(user.getId());

在我的測試中,我創建了一個

User user = mock(User.class) // interface of user
when(user.getId()).thenReturn(new Integer(111)));

我不明白我在做什么錯。任何幫助將不勝感激!

謝謝

我相信這是怎么回事,您還沒有向測試中的類提供user模擬。

暫無
暫無

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

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