0

I'm following this guide http://javaeenotes.blogspot.com/2011/06/short-introduction-to-jmock.html

I've received the error

java.lang.SecurityException: class "org.hamcrest.TypeSafeMatcher"'s signer information does not match signer information of other classes in the same package.

In the guide the author says:

The solution is make sure the jMock libraries are included before the standard jUnit libraries in the build path.

What makes up the "standard jmock libraries" and the "junit libraries"? Junit only has one jar so that's easy, but jmock comes with over 10 different jars.

I've been using: j-unit4.10, jmock-2.5, hamrest-core and hamcrest-library

What are the hamcrest core and library classes for?

Eric Francis
  • 23,039
  • 31
  • 88
  • 122

3 Answers3

1

i'm a committer on both libraries. JMock depends on hamcrest to help it decide whether an call to an object is expected. I suggest just using the hamcrest-all jar. The split between hamcrest core and library was to separate the fundamental behaviour of matching and reporting differences from a convenient implementations of the most common cases.

Finally, if you're using hamcrest, I suggest you use the junit-dep jar to avoid clashes with some features of hamcrest that are included in the junit.jar

Steve Freeman
  • 2,707
  • 19
  • 14
0

JUnit is used to do Unit test in order to test your methods. JMock is used to test your program inside a context, You will have to know what you are expecting to send to the context (ENV) and what will answer the context.

JMock use JUnit, that is why, in order to avoid dependency conflicts, you need to include it before JUnit.

The 10 libraries of JMock are kind of add-ons if you need to use JMock script or any other functionnality not available in the JMock core.

You don't need to know about Hamcrest-core library to use JMock. Just follows the guide on the web site (don't use version 1 of JMock) and Organize your libraries in the correct order (JUnit should be last in order to avoid your error)

Baptiste Gousset
  • 251
  • 2
  • 16
0

mock frameworks licke jmock do some black magic behind the scenes ( including, but not limited to runtime byte code manipulation ) to provide mock methods classes and whatever. To be able to do this, some tweaks in basic junit classes are necessary, and the only way to do this is to register itself as java agent before JU classes are loaded.

Also, put your mock framework before junit in classpath

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35