junit and hamcrest declaration

我只是一个虾纸丫 提交于 2020-01-14 07:59:13

问题


I am using junit at 4.10 and declared hamcrest-core at 1.3 and hamcrest-library at 1.3. My question is are hamcrest-library and hamcrest-core embedded in junit 4.10. what about junit 4.11?

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

回答1:


If you browse to search.maven.org you can search for artifacts and see their dependencies. If you are using Eclipse wit the Maven plugin, you can also click Dependency Hierarchy in the POM editor.

Looking on the Maven website you can see that JUnit 4.11 depends on Hamcrest 1.3:

<dependencies>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
      <version>1.3</version>
      <scope>compile</scope>
    </dependency>
</dependencies>

Hamcrest library you have to add yourself.




回答2:


JUnit 4.10 & JUnit 4.11 (as depicted below):

   <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

... ship with the hamcrest-core 1.1 and 1.3 respectively. You can see this for yourself by leveraging the dependency plugin's tree goal (running mvn dependency:tree):

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building testng 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ testng ---
[INFO] testng:testng:jar:1.0-SNAPSHOT
[INFO] \- junit:junit:jar:4.10:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.483s
[INFO] Finished at: Fri Mar 29 12:07:22 MDT 2013
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------

As silly as this sounds, you need to include the appropriate hamcrest-library artefact to take advantage of the Hamcrest Matchers. Hopefully this helps...



来源:https://stackoverflow.com/questions/15660807/junit-and-hamcrest-declaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!