Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol Mock or InjectMocks

I am using Intellij, and my external dependencies folder show I am using mockito-all-1.10.19.jar.

I am using this simple Mockito example.

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class AuditUnitTests {

    @Mock
    AuditTwo two;

    @InjectMocks
    AuditOne one;

    @Test
    public void test1() {
        one.sayHelloFilter("Saurav");
        one.sayHelloFilter("Dravid");
        one.sayHelloFilter("Sachin");
        verify(two, times(2)).sayHello();
    }
}

However my Intellij complains that It cannot resolve Mock and InjectMocks annotations. How can I resolve it ?

Note: I am using Ivy for dependency management:

   <dependency org="junit" name="junit" rev="4.12" conf="test"/>
    <dependency org="org.mockito" name="mockito-all" rev="1.10.19" conf="test"/>
like image 271
JavaDeveloper Avatar asked Feb 06 '23 09:02

JavaDeveloper


1 Answers

Your static import is not sufficent. You have to add following additional imports.

import org.mockito.InjectMocks;
import org.mockito.Mock;
like image 128
Paul Wasilewski Avatar answered Feb 11 '23 19:02

Paul Wasilewski