For example, this test case
@Test public void testFail() { Assert.assertThat("oh hello yeah", CoreMatchers.containsString("hello")); }
fails with:
java.lang.LinkageError: loader constraint violation: loader (instance of sun/misc/Launcher$AppClassLoader) previously initiated loading for a different type with name "org/hamcrest/Matcher" at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
This is due to the way that our TestRunner does class loading: it accepts only classes from org.junit. Junit, however, exposes org.hamcrest in its API, and thus when we load junit, we also load hamcrest. Then, in the test case itself, when the user code uses hamcrest classes, they are loaded with a different class loader and that does not match. The error message from Java is slightly misleading.