【问题标题】:Why am I getting InvalidUseOfMatchers build error here?为什么我在这里收到 InvalidUseOfMatchers 构建错误?
【发布时间】:2018-03-04 08:07:54
【问题描述】:

这段代码可以很好地编译和调试,但是当我在 Eclipse 中进行 maven 构建时,单元测试和构建失败。我不明白这里匹配器的滥用在哪里?谢谢。

[ERROR] 错误:[ERROR] 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();
 }
}

【问题讨论】:

  • 这是all异常所说的吗?只是“InvalidUseOfMatchers”?还是有更多解释?哪里抛出异常?
  • (我承认我并不清楚你在这里要测试什么......)
  • 能否请您过去整个堆栈跟踪或错误消息。

标签: java mockito junit4 matcher


【解决方案1】:

感谢您的帮助,没错,这就是例外的全部内容。解决方法是在 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>  

【讨论】:

    猜你喜欢
    • 2019-09-09
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    相关资源
    最近更新 更多