Use Junit with EsIntegTestCase

Hi,

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:

@ClassRule
public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();

@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();

However, I get the following exception:

SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@2fb9ec94] to prepare test instance [TestDAL@1b416347]
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)

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,

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 (https://www.elastic.co/guide/en/elasticsearch/reference/current/integration-tests.html)
is confusing for me. Should it be marked as deprecated?

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

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