# ES 5.0 Java testing using ESIntegTestCase not supported in TestNg?

**URL:** <https://discuss.elastic.co/t/es-5-0-java-testing-using-esintegtestcase-not-supported-in-testng/64850>\
**Category:** Elasticsearch\
**Created:** [November 3, 2016, 11:34am UTC](https://discuss.elastic.co/t/es-5-0-java-testing-using-esintegtestcase-not-supported-in-testng/64850 "2016-11-03T11:34:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![escay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/escay/32/12344_2.png) [@escay](https://discuss.elastic.co/u/escay)\
**Post date:** [November 3, 2016, 11:34am UTC](https://discuss.elastic.co/t/es-5-0-java-testing-using-esintegtestcase-not-supported-in-testng/64850/1 "2016-11-03T11:34:45Z")

</div>

I cannot seem to get a simple EsIntegrationTest to work in TestNg.  
I get all kinds of java.security.AccessControlException exceptions.

## Failing TestNg example

pom.xml:

```
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.dummy</groupId>
  <artifactId>test.es.integration.tests</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.8</version>
            <scope>test</scope>
        </dependency>

        <!-- ElasticSearch integration tests -->
        <dependency>
            <groupId>org.elasticsearch.test</groupId>
            <artifactId>framework</artifactId>
            <version>5.0.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.6.2</version>
            <scope>test</scope>
        </dependency>
  </dependencies>
</project>

```

Example integration test class:

```
package com.dummy;

import java.io.IOException;
import java.net.URISyntaxException;

import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.test.ESIntegTestCase;
import org.testng.annotations.Test;

public class EsIntegrationTest extends ESIntegTestCase {

    @Test
    public void createIndexTest() throws IOException, URISyntaxException {
        Client client = ESIntegTestCase.client();
        assertNotNull(client);

        final String indexName = "testindex";
        final CreateIndexResponse createIndexResponse = client.admin().indices().prepareCreate(indexName).execute()
                .actionGet();

        if (!createIndexResponse.isAcknowledged()) {
            fail("Could not create index: " + indexName);
        }
    }
}

```

mvn test fails with:

```
Running com.dummy.EsIntegrationViaJUnitTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@2a33fae0
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) 
...
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "F:\test.es.integration.tests\target\surefire-reports\com.dummy.EsIntegrationViaJUnitTest" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
...

```

## JUnit works fine

Example pom:

just remove the testng dependency from the example above

```
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.8.8</version>
                <scope>test</scope>
            </dependency>

```

Test class:

replace the Test import with

`import org.junit.Test;`

the JUnit test starts an ES node, runs the test and succeeds.  
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.151 sec

## Question

Does this mean TestNg is not supported?

Which means I cannot migrate from 2.3 (where I still used the NodeBuilder to start ES test instances for my integration tests) to 5.0 which requires me to use ESIntegTestCase because there is no NodeBuilder alternative anymore.  
I cannot switch from TestNg to JUnit, there are to much integration tests in my product that would require a rewrite.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 3, 2016, 1:15pm UTC](https://discuss.elastic.co/t/es-5-0-java-testing-using-esintegtestcase-not-supported-in-testng/64850/2 "2016-11-03T13:15:41Z")

</div>

TestNg isn't supported. ESIntegTestCase uses [randomized testing](https://labs.carrotsearch.com/randomizedtesting.html) which is an extension to junit. At this point it may be easier for you to move to an Elasticsearch instance that you start as part of the build, preferably forking your build to run the startup scripts.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [November 3, 2016, 1:33pm UTC](https://discuss.elastic.co/t/es-5-0-java-testing-using-esintegtestcase-not-supported-in-testng/64850/3 "2016-11-03T13:33:17Z")

</div>

This is still fairly ongoing:

> <https://github.com/alexcojocaru/elasticsearch-maven-plugin/pull/19>

  

> <https://github.com/elastic/elasticsearch/issues/21119>

---

<div class="post-metadata">

**Author:** ![escay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/escay/32/12344_2.png) [@escay](https://discuss.elastic.co/u/escay)\
**Post date:** [November 3, 2016, 3:00pm UTC](https://discuss.elastic.co/t/es-5-0-java-testing-using-esintegtestcase-not-supported-in-testng/64850/4 "2016-11-03T15:00:05Z")

</div>

Thank you for the links. Starting an Elasticsearch instance before my tests run is ok for me, I currently do this in 2.4.1 using NodeBuilder.

I also tried running JUnit inside TestNG using [http://testng.org/doc/documentation-main.html#junit](http://testng.org/doc/documentation-main.html#junit) but this does not seem to be very mature.

---

<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:** [July 5, 2017, 10:06pm UTC](https://discuss.elastic.co/t/es-5-0-java-testing-using-esintegtestcase-not-supported-in-testng/64850/5 "2017-07-05T22:06:54Z")

</div>


