Hamcrest - 使用什么版本?1.3或2

ben*_*ben 31 java junit hamcrest

我很困惑.目前我正在测试我的弹簧应用程序

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

只要我想匹配RegularExpressions,我就很开心.在hamcrest 1.3中你需要编写自己的匹配器,我不喜欢这么多.我搜索并发现hamcrest 2.0内置了一些内容,例如:

assertThat(DateHelper.getActualDateForXML(), MatchesPattern.matchesPattern("\\d{4}+-\\d{2}-+\\d{2}+T\\d{2}+:\\d{2}+:\\d{2}+"));
Run Code Online (Sandbox Code Playgroud)

我很高兴,我补充说:

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-junit</artifactId>
    <version>2.0.0.0</version>
    <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

并从spring-boot-starter-test中踢出了1.3个hamcrest依赖项:

<exclusions>
    <exclusion>
       <groupId>org.hamcrest</groupId>
       <artifactId>hamcrest-library</artifactId>
    </exclusion>
    <exclusion>
       <groupId>org.hamcrest</groupId>
       <artifactId>hamcrest-core</artifactId>
    </exclusion>
</exclusions>
Run Code Online (Sandbox Code Playgroud)

现在一切都在按照我的预期工作,但我觉得不舒服.因为我可以找到写大约1.3的人,并且无法真正找到使用hamcrest-junit 2.0.

有人可以解释一下他们之间的联系吗?因为看起来hamcrest-junit 2.0的所有内容都来自hamcrest 1.3 ......

谢谢Ben

Ivo*_*ori 36

基于Hamcrest Github

JUnit Lambda(Junit 5)

我接受了

  • hamcrest-junit 2.0(应该是)是一个新的开始,也是将hamcrest与junit分离的目标
  • 与此同时,Junit 5项目启动了(也希望)减少/删除第三方依赖项

=>在这种情况下,我认为对于Hamcrest家伙来说,等待/协调JUnit 5项目然后大幅前进是明智的.

正如@heenenee所提到的那样,这些家伙忙于处理其他事情,所以这个项目并没有多少发生.

回答

有人可以解释一下他们之间的联系吗?因为看起来hamcrest-junit 2.0的所有内容都来自hamcrest 1.3

  • hamcrest-junit 2.0已经开始,但背后的人们很快就会忙着(现在还有)其他项目,所以开发停止了
  • 关于JUnit 5可能还存在一些不确定因素,这可能会促使将hamcrest-junit 2.0的进一步推迟到JUnit 5的发布(推测)

......但我感觉不舒服.因为我可以找到写大约1.3的人,并且无法真正找到使用hamcrest-junit 2.0.

目前,除了你的情况,没有太大的动力转移到hamcrest-junit 2.0.一旦Junit 5发布,我预计会有更多的动力再次前进.


dsc*_*ten 7

Hamcrest项目刚刚发布了2.1,经过深思熟虑,他们重新设计了包结构。确保遵循升级过程。现在将工件java-hamcrest 2.0.0.0视为失败尝试