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

问题描述 投票:27回答:3

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

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
</dependency>

只要我想匹配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}+"));

我很高兴,我补充说:

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-junit</artifactId>
    <version>2.0.0.0</version>
    <scope>test</scope>
</dependency>

并从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>

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

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

谢谢Ben

java junit hamcrest
3个回答
35
投票

基于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发布,我预计会有更多的动力再次前进。


6
投票

Hamcrest项目只有released 2.1,他们在reworked the package structurethorough consideration。确保你遵循upgrade procedure。工件java-hamcrest 2.0.0.0现在被认为是failed attempt


3
投票

Ivo给出了很好的答案,这真的应该得到更多的选票,但这里有一些补充信息。如果你检查Maven有关依赖关系的信息,Java Hamcrest 2.0.0.0Hamcrest JUnit 2.0.0.0,有一些usage链接。在我写这篇文章时,它分别是74和68,并且没有简短浏览的重大项目。

© www.soinside.com 2019 - 2024. All rights reserved.