Test framework library for Elasticsearch providing comprehensive testing utilities, base test classes, cluster management, and assertion helpers for unit and integration testing of Elasticsearch plugins and applications
npx @tessl/cli install tessl/maven-org-elasticsearch--elasticsearch-test-framework@9.0.0The Elasticsearch Test Framework (org.elasticsearch.test:framework) provides comprehensive testing utilities for Elasticsearch development. This framework includes 386+ classes organized into specialized testing packages, offering everything from basic unit test utilities to complex multi-node integration testing capabilities.
Package Name: elasticsearch-test-framework
Package Type: maven
Language: Java
Group ID: org.elasticsearch
Artifact ID: elasticsearch-test-framework
Installation: Add to Maven pom.xml:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-test-framework</artifactId>
<version>9.0.3</version>
<scope>test</scope>
</dependency>Or to Gradle build.gradle:
testImplementation 'org.elasticsearch:elasticsearch-test-framework:9.0.3'This testing framework is built on top of Apache Lucene's testing infrastructure and extends it with Elasticsearch-specific functionality. It provides mock implementations, specialized assertion utilities, cluster management capabilities, and data generation tools designed specifically for testing Elasticsearch functionality.
// Core package structure
org.elasticsearch.test
├── ESTestCase // Base class for all Elasticsearch unit tests
├── ESIntegTestCase // Base class for integration tests
├── InternalTestCluster // Multi-node test cluster management
├── SingleNodeTestCase // Single node test scenarios
└── hamcrest/ // Custom Hamcrest matchers
└── ElasticsearchAssertions // Elasticsearch-specific assertionsThe framework follows a layered architecture:
Standard import patterns for using the Elasticsearch Test Framework:
// Core test base classes
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESSingleNodeTestCase;
// Cluster management
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.TestCluster;
// Custom assertions and matchers
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
// Common Hamcrest matchers
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
// Mock implementations
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.test.store.MockDirectoryWrapper;ESTestCase provides randomized testing with Elasticsearch-specific setupESIntegTestCase manages full Elasticsearch clustersSingleNodeTestCase for lightweight integration scenariosorg.elasticsearch.test)import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.SingleNodeTestCase;org.elasticsearch.test.hamcrest)import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.hamcrest.OptionalMatchers;
import org.elasticsearch.test.hamcrest.TupleMatchers;org.elasticsearch.test.transport, org.elasticsearch.common.settings)import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.test.store.MockDirectoryWrapper;org.elasticsearch.test.disruption)import org.elasticsearch.test.disruption.NetworkDisruption;
import org.elasticsearch.test.disruption.ServiceDisruptionScheme;
import org.elasticsearch.test.disruption.SingleNodeDisruption;org.elasticsearch.test.rest)import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.test.rest.RestTestExecutionContext;org.elasticsearch.logsdb.datageneration)import org.elasticsearch.logsdb.datageneration.DocumentGenerator;
import org.elasticsearch.logsdb.datageneration.FieldDataGenerator;
import org.elasticsearch.logsdb.datageneration.DataGenerator;import org.elasticsearch.test.ESTestCase;
public class MyElasticsearchTest extends ESTestCase {
public void testBasicFunctionality() {
String randomValue = randomAlphaOfLength(10);
int randomInt = randomIntBetween(1, 100);
// Your test logic here
assertThat(randomValue, notNullValue());
assertThat(randomInt, allOf(greaterThan(0), lessThanOrEqualTo(100)));
}
}import org.elasticsearch.test.ESIntegTestCase;
public class MyIntegrationTest extends ESIntegTestCase {
public void testClusterOperations() {
createIndex("test-index");
ensureGreen("test-index");
// Index a document
client().prepareIndex("test-index")
.setSource("field", "value")
.get();
// Search and verify
SearchResponse response = client().prepareSearch("test-index")
.get();
assertThat(response.getHits().getTotalHits().value, equalTo(1L));
}
}This comprehensive documentation is organized into focused areas:
Each section provides detailed API documentation, usage examples, and best practices for effective Elasticsearch testing.
The Elasticsearch Test Framework is designed around several key principles:
This framework enables comprehensive testing of Elasticsearch functionality from simple unit tests to complex distributed scenarios, ensuring robust and reliable Elasticsearch deployments.