InMemoryConnection for unit testing Elasticsearch projects
Is it good to use a class InMemoryConnection
for unit testing our Elasticsearch projects?
This class is used in the actual source code for unit testing. But the reason I am asking is because it comes from HttpConnection
. I'm not really sure if it opens any HTTP connection. Our unit tests go to the build server, so I would like to avoid that. Thanks for the help.
source to share
Yes.
If you look at the implementation InMemoryConnection
, you can see that it overrides DoSynchronousRequest and DoAsyncRequest (the methods HttpConnection
that are responsible for making the HTTP request) and just returns a fake one ElasticsearchResponse
. HTTP connections are not open and no requests are made, so you can use them in your unit tests.
source to share
However, there is a NuGet package for real C # integration tests: https://www.nuget.org/packages/elasticsearch-inside/
(I am the author)
source to share