簡體   English   中英

Junit測試在程序包上運行時失敗,但在文件上運行時成功

[英]Junit test fails when run on package, but success when run on file

大更新:之前有人遇到過嗎?

我在Maven項目中使用JUnit 4.5和Mockito 1.7。

我在testCaseFolder軟件包中有testCaseA.java。 如果我打開testCaseA.java,右鍵單擊代碼,選擇“運行方式”-“ Junit測試”就可以了。 但是,如果我右鍵單擊程序包,選擇“運行方式”-“ Junit測試”,它將失敗:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Misplaced argument matcher detected!
Somewhere before this line you probably misused Mockito argument matchers.
For example you might have used anyObject() argument matcher outside of verification or stubbing.
Here are examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"));
    at testCaseA.setUP(testCaseA.java:33) 

第33行是: //MockitoAnnotations.initMocks(this);***//it said this is error***

這是代碼:

SomeService service;
@Mock
private CommonService commonService;
@Mock
public Errors errors;

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);***//it said this is error***
}

@Test
public void testvalidate() {
    //fail even here is empty
}

從錯誤更新您得到的應該是正確的。

您的Mockito.when陳述有誤。

Mockito.when(commonService.get(Mockito.eq(contactGroupId))).thenReturn(disseminationProfile);

要么

Mockito.when(commonService.get(Mockito.anyLong())).thenReturn(disseminationProfile); 

暫無
暫無

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

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