# Use Junit with EsIntegTestCase

**URL:** <https://discuss.elastic.co/t/use-junit-with-esintegtestcase/132061>\
**Category:** Elasticsearch\
**Created:** [May 16, 2018, 8:37am UTC](https://discuss.elastic.co/t/use-junit-with-esintegtestcase/132061 "2018-05-16T08:37:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xam](https://avatars.discourse-cdn.com/v4/letter/x/bb73d2/32.png) [@xam](https://discuss.elastic.co/u/xam)\
**Post date:** [May 16, 2018, 8:37am UTC](https://discuss.elastic.co/t/use-junit-with-esintegtestcase/132061/1 "2018-05-16T08:37:03Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 16, 2018, 8:53am UTC](https://discuss.elastic.co/t/use-junit-with-esintegtestcase/132061/2 "2018-05-16T08:53:40Z")

</div>

You should better start an external elasticsearch instance IMO. Have a look at [In memory testing with RestHighLevelClient](https://discuss.elastic.co/t/in-memory-testing-with-resthighlevelclient/106196/6)

---

<div class="post-metadata">

**Author:** ![xam](https://avatars.discourse-cdn.com/v4/letter/x/bb73d2/32.png) [@xam](https://discuss.elastic.co/u/xam)\
**Post date:** [May 16, 2018, 3:29pm UTC](https://discuss.elastic.co/t/use-junit-with-esintegtestcase/132061/3 "2018-05-16T15:29:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 16, 2018, 3:46pm UTC](https://discuss.elastic.co/t/use-junit-with-esintegtestcase/132061/4 "2018-05-16T15:46:38Z")

</div>

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

---

<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:** [June 13, 2018, 3:46pm UTC](https://discuss.elastic.co/t/use-junit-with-esintegtestcase/132061/5 "2018-06-13T15:46:39Z")

</div>

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