Use Junit with EsIntegTestCase



I want to perform integration test with JUnit. My test class inherits from ESIntegTestCase. But I also want my test resolves Spring bean.
For my first try, I used the SpringJUnit4ClassRunner but it failed, as the Spring Runner overrides the RandomizedRunner from Elasticsearch. Then I tried to add the two following attributes, that can be used to run Spring test without using the SpringRunner:

public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();

public final SpringMethodRule springMethodRule = new SpringMethodRule();

However, I get the following exception:

SEVERE: Caught exception while allowing TestExecutionListener [] to prepare test instance [TestDAL@1b416347]
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
at java.lang.SecurityManager.checkPermission(

If I remove the "extends ESIntegTestCase", it works: but of course, it is not what I am looking for.

Do you know how to combine EsIntegTestCase with another Runner, such as the Spring Runner to perform integration test of ES in a project that uses the Spring Framework?

Thank you,

(David Pilato) #2

You should better start an external elasticsearch instance IMO. Have a look at In memory testing with RestHighLevelClient


Ok thank you for your answer : I'll used the mvn plugin instead.
The integration test page (
is confusing for me. Should it be marked as deprecated?

(David Pilato) #4

I think this page can work with Gradle. I think @rjernst already answered that somewhere on this forum.

(system) #5

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