Could not initialize class org.elasticsearch.test.ESTestCase alternate solution

I've seen two forum messages related to errors starting up ESTestCase and ESIntegTestCase:

In the first, a resolution was never fully suggested; the second has potentially misleading guidance. Because the forum locks old threads, there is no way for me to correct or augment those with information so I've started a new thread in the hopes that future Google searches might run across this instead and help guide people towards the solution that worked for me.

As with the reported errors, I was getting this error when trying to run ESTestCase

Exception in thread "Thread-4" java.lang.NoClassDefFoundError: Could not initialize class 
org.elasticsearch.test.ESTestCase
        at java.lang.Thread.run(Thread.java:748)
        Suppressed: java.lang.IllegalStateException: No context information for thread: Thread[id=23, 
name=Thread-4, state=RUNNABLE, group=TGRP-MyTestCase]. Is this thread running under a class 
com.carrotsearch.randomizedtesting.RandomizedRunner runner context? Add @RunWith(class 
com.carrotsearch.randomizedtesting.RandomizedRunner.class) to your test class. Make sure your 
code accesses random contexts within @BeforeClass and @AfterClass boundary (for example, static 
test class initializers are not permitted to access random contexts).
                at 
com.carrotsearch.randomizedtesting.RandomizedContext.context(RandomizedContext.java:248)
                at 
com.carrotsearch.randomizedtesting.RandomizedContext.current(RandomizedContext.java:134)
                at 

com.carrotsearch.randomizedtesting.RandomizedRunner.augmentStackTrace(RandomizedRunner.java:1
848)
at

com.carrotsearch.randomizedtesting.RunnerThreadGroup.uncaughtException(RunnerThreadGroup.java:
20)
at java.lang.Thread.dispatchUncaughtException(Thread.java:1959)

When trying to run ESIntegTestCase the same error would be preceeded by:

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the 
classpath. Using SimpleLogger to log to the console...

The misleading part about the previous forum post is that the StatusLogger error is not causing the issues, it's simply stating that it's falling back to use SimpleLogger instead. Using ./gradlew test --info the root cause becomes more apparent.

java.lang.RuntimeException: found jar hell in test classpath

I resolved my issue by changing this line in my build.gradle:

testCompile junit:junit:4.12

to:

testCompile ('junit:junit:4.12') {
    exclude module : 'hamcrest'
    exclude module : 'hamcrest-core'
}

Then cleaning my Gradle caches and rebuilding.

YMMV

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.