首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mockito,JUnit,Hamcrest,版本控制

Mockito,JUnit,Hamcrest,版本控制
EN

Stack Overflow用户
提问于 2013-09-12 17:43:18
回答 3查看 8.1K关注 0票数 21

默认情况下,所需的Hamcrest版本用于:

  • JUnit 4.11
    • Hamcrest 1.3

  • Mockito 1.9.5
    • Hamcrest 1.1

Hamcrest 1.1和1.3之间没有insiginifcant变化。目前,我的测试用例试图使用Hamcrest 1.1运行JUnit 4.11,但出于类似的原因,我合理地是当然这是个坏主意。,我怀疑尝试在Hamcrest 1.3中使用Mockito 1.9.5是也是个坏主意。

该怎么办呢?

  1. 与最新的JUnit和Mockito一起使用Hamcrest 1.1
  2. 与最新的JUnit和Mockito一起使用Hamcrest 1.3
  3. 尝试修补Mockito 1.9.5使用Hamcrest 1.3
    • 我现在还没有时间

  1. 使用JUnit 4.10
  2. 另一个?

更新2015-06-12:和Mockito 1.10.19和2.0.13-beta仍然使用Hamcrest 1.1

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-09-12 17:53:26

2015年7月29日@durron597更新:这一极好的答案在2013年是正确的,但后来由于对Mockito的更新而变得过时。看看这个答案。

我在工作中的许多Maven项目中使用带有Mockito核心依赖项和hamcest1.3的最新JUnit。到目前为止,还没有人报告这方面有任何问题。因此,如果这适用于您的测试,那么与所有这三种测试的最新版本一起使用。只需确保使用mockito核心而不是所有。

因此,我建议采用选项2,以获得更新版本的所有好处。如果你真的怀疑任何事情都可能出错,使用选项4,这是最安全的。当然,你可以选择选项2,在不久的将来,任何事情都会出错,你可以切换到选项2,或者从那时起,一个新的模型就已经解决了这个问题。

来自mockito问题397的注意:这个问题不会出现在mockito核中。

票数 13
EN

Stack Overflow用户

发布于 2014-06-30 12:07:23

这是[医]味精建议的Maven解决方案

代码语言:javascript
复制
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-all</artifactId>
      <version>1.3</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <exclusions>
        <exclusion>
          <artifactId>hamcrest-core</artifactId>
          <groupId>org.hamcrest</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>1.9.5</version>
      <exclusions>
        <exclusion>
          <groupId>org.hamcrest</groupId>
          <artifactId>hamcrest-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-all</artifactId>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>
票数 4
EN

Stack Overflow用户

发布于 2013-09-12 17:50:17

查看Mockito文档这里,我认为选项2是推荐的方法(使用mockito核心工件)。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18770943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档