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

**URL:** <https://discuss.elastic.co/t/could-not-initialize-class-org-elasticsearch-test-estestcase-alternate-solution/117641>\
**Category:** Elasticsearch\
**Created:** [January 30, 2018, 2:45pm UTC](https://discuss.elastic.co/t/could-not-initialize-class-org-elasticsearch-test-estestcase-alternate-solution/117641 "2018-01-30T14:45:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Ihde](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Michael\_Ihde](https://discuss.elastic.co/u/Michael_Ihde)\
**Post date:** [January 30, 2018, 2:45pm UTC](https://discuss.elastic.co/t/could-not-initialize-class-org-elasticsearch-test-estestcase-alternate-solution/117641/1 "2018-01-30T14:45:03Z")

</div>

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

- [https://discuss.elastic.co/t/could-not-initialize-class-org-elasticsearch-test-estestcase/78770](https://discuss.elastic.co/t/could-not-initialize-class-org-elasticsearch-test-estestcase/78770)

- [https://discuss.elastic.co/t/how-to-use-esintegtestcase-in-elasticsearch-5-6-3/104787](https://discuss.elastic.co/t/how-to-use-esintegtestcase-in-elasticsearch-5-6-3/104787)

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 27, 2018, 2:45pm UTC](https://discuss.elastic.co/t/could-not-initialize-class-org-elasticsearch-test-estestcase-alternate-solution/117641/2 "2018-02-27T14:45:03Z")

</div>

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