문제

Big update: Has anyone run into this before?

I'm using JUnit 4.5 and Mockito 1.7 in a Maven project.

I have testCaseA.java in package testCaseFolder. if I open testCaseA.java, right click in the code, select "Run as" -"Junit test" it is okay. But if I right click package, select "Run as" -"Junit test", it will fail:

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) 

Line 33 is: //MockitoAnnotations.initMocks(this);***//it said this is error***

Here is the code:

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
}
도움이 되었습니까?

해결책

Update from the error your getting this should be correct.

Your Mockito.when statement is wrong.

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

Or

Mockito.when(commonService.get(Mockito.anyLong())).thenReturn(disseminationProfile); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top