我正在使用@Mock
注解来模拟一个对象
@Mock
Customer customer;
但是@Mock
注解显示警告。
MockitoAnnotations.Mock
类型已过时。
我的测试用例失败了。
使用
MockitoAnnotations.openMocks(this);
您使用了错误的模拟对象。请尝试使用以下模拟对象:
org.mockito.Mock
,而不是org.mockito.MockitoAnnotations.Mock
@BeforeEach
void init() {
MockitoAnnotations.initMocks(this);
}
并将其替换为类内的此规则
@Rule //initMocks
public MockitoRule rule = MockitoJUnit.rule();
testImplementation 'org.powermock:powermock-api-mockito2:2.0.2'
,其中它是mockito2。openMocks(this)
进行了管理。 - Douglas Mesquita