In our (Java) unit tests we would like to test the integration of Elasticsearch (e.g. do queries work, can docs be indexed correctly, etc.). I'm wondering if there are any best practices or recommendations regarding this topic?
Here are some additional thoughts/questions from my side:
My preferred solution would be to run the test against a real, "always-running" Elasticsearch instance. However in our current company/environment this is not possible.
For certain ORMs (e.g. Entity Framework in the dotnet world) there exist in-memory representations that are meant to be used for tests. Is there something similar in the elastic world?
I found the ESSingleNodeTestCase-class. However I didn't find much documentation nor any examples, etc. Plus I read that it can be quite tedious to set up. Is This still supported and recommended?
The requirement is that these tests can be executed locally (e.g. in IntelliJ) as well as on our build server.
Use the Gradle tools elasticsearch already has. You can read some information about this here: #21119. This sample project shows how to use Elasticsearch Test Classes
Thanks a lot for your quick reply. I agree that unit tests should not access or require any third party tool. On the other hand I think it's helpful to unit test in a "as real as possible"-situation. That's why some kind of in-memory or something like that would be cool.
Would that maybe be possible with the ESSingleNodeTestCase?
As far as I can see, all the mentioned solutions require Docker or download some other stuff.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.