1

I'm using Spring Boot with elasticsearch-rest-high-level-client and I am currently writing unit tests.

My program is just a simplified REST API to call ES, thus my unit tests need either a mock of the ES database or a running ES instance and so far I haven't been able to do any these.

Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
Freaka
  • 43
  • 1
  • 6

1 Answers1

0

In fact, if you really write unit tests, they can't use any database or instance (or they are been integration tests).

I recommend to google how testing Spring Rest Client for example, WireMock, or this question. You just define what results you want from Elasticsearch.

If you really need integration tests, you can create any ES demo instance.

Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
  • I'll have a look, thanks. I understand this isn't unit testing but so far it's the only relevant testing I thought of regarding my application. – Freaka Nov 30 '18 at 15:33
  • So I am using WireMock now and I am rather satisfied, thanks a lot. Only disturbing thing I found, but it could be related to elasticsearch high level rest client or just me misusing things : I have to stubFor a post method to mock my update call and stubFor a put method to mock my create call. – Freaka Dec 05 '18 at 15:45