该代码可以很好地编译和调试,但是当我在Eclipse中进行Maven构建时,单元测试和构建失败。我不知道这里的匹配器滥用在哪里?谢谢。
[错误]错误:[错误] Tests.MyTest()»InvalidUseOfMatchers
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {MapperFactory.class})
public class Tests {
@Mock private Bucket bucketMock;
@Mock private MutateInBuilder builderMock;
@InjectMocks private Repository couchbaseRepository;
private MapperFactory mapperFactory;
@Autowired
public void setMapperFactory(MapperFactory mapperFactory) {
this.mapperFactory = mapperFactory;
}
@Test
public void MyTest() throws MyException {
String jsonText = jsonSamples.getProperty("theJson");
Mapper mapper = mapperFactory.getMapper(JsonObject.fromJson(jsonText),repository);
when(bucketMock.mutateIn("1234")).thenReturn(builderMock);
mapper.execute();
verify(builderMock).execute();
}
}
最佳答案
谢谢您的帮助,这项权利就是例外。解决方案是在pom.xml文件中更新Mockito的artifactId:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
被替换为:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
</dependency>