Having trouble implementing custom hamcrest matcher to use in Grails. Running the tests using my matcher fails with:

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V

After a bit of googling it seems that this is caused by the order of the loaded libraries: JUnit and Hamcrest. I have added the following dependency to my BuildConfig.groovy:

dependencies {
  test 'org.hamcrest:hamcrest-all:1.3'
}

Accordingly to instructions I was able to found, this could be fixed by making sure that hamcrest classes are loaded before JUnit ones. I do not know how to achieve this in Grails though or how to solve this in any other way.

Using Grails 2.2.1

有帮助吗?

解决方案

This depends on the version of JUnit you're using. You can check this by looking in lib/junit/junit/jars. I think this is 4.10 by default. If so, please upgrade to 4.11. You can do this by explictly specifying it in the BuildConfig.groovy I believe:

dependencies {
  test 'junit:junit:4.11'
  test 'org.hamcrest:hamcrest-all:1.3'
}

For an explanation, before 4.11 a version of the hamcrest libraries were included in the JUnit distribution. This is no longer the case with 4.11, and you sometimes get a mismatch between class versions.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top