How do I test a function which returns a complex object? How do I test a function which returns a complex object? elasticsearch elasticsearch

How do I test a function which returns a complex object?


IHMO, writing unit tests for built Elastic queries don't make really sense.
It is exactly as if you want to test a JPA query not against the response returned by the Database but against the text of the query.
How to ensure that it is correct when executed against your ElasticSearch DB and that it is valid in terms of syntax too ?

I think that similarly to DB queries, Elastic queries testing makes more sense as integration tests.
Unfortunately, I didn't have the occasion to setup that in my Elastic devs where I worked on but you can get some feedback here and from that post, some ideas :

Use the Gradle tools elasticsearch already has. You can read someinformation about this here:https://github.com/elastic/elasticsearch/issues/21119 620

Use the Maven plugin:https://github.com/alexcojocaru/elasticsearch-maven-plugin 785

Use Ant scripts likehttp://david.pilato.fr/blog/2016/10/18/elasticsearch-real-integration-tests-updated-for-ga

Using Docker: https://www.testcontainers.org/modules/elasticsearch

Using Docker from maven:https://github.com/dadoonet/fscrawler/blob/e15dddf72b1ed094dad279d492e4e0314f73683f/pom.xml#L241-L28992