I have created a custom Elastic Search Client. I need to deploy unit testing on the various functions. How should I do that?
Say for example , in JUnit I use these ->
assertEquals(expectedOutput, actualOutput);
The problem here is that there is actually no return value. The queries execute and manipulate things. I want to unit test the various functions.
For example, I want to see if the index() works properly. I don't really want to actually index data and check if it has been indexed as I am not doing the integration testing right now. Can I do just unit testing?
Following is a method from my client. How should I deploy unit testing here?
@Override
public ActionFuture<IndexResponse> index(IndexRequest request)
{
TimerContext indexTimerContext=indexTimer.time();
super.index(request));
indexTimerContext.stop();
}
How should I really go about doing it?
ElasticSearch has its own Test Framework and ( assertion ) tutorial describes unit and integration testing! If you want to use other framework you could use mockito or easymock. In your case you have to check that method
index(IndexRequest request)
callsindexTimer.time()
andindexTimerContext.stop()
therefore you must mockindexTimer
and verify call. look at Java verify void method calls n times with MockitoEDIT I have never work with ElasticSearch, but your unit test will look like this