With Java I can write tests against an embedded elasticsearch node, this gives me loads of testing possibilities such as testing index config and tokenizers however more importantly I can test my search services with functional, easy to read and effective tests, no mocking of the client and dealing with query builders and responses in my tests etc. How can I do this in .NET?
You can't run in embedded mode with .NET you will have to speak with an elasticsearch server somewhere.
Using nest you can easily talk to a different index specifically for testing i.e
var uri = new Uri("http://localhost:9200");
var connectionSettings = new ConnectionSettings(uri, "my-test-index");
var client = new ElasticClient(connectionSettings);
my-test-index
will now be used as index for every call which doesn't explicitly specify one. Depending on how invasive your tests are you could even create an index suffixed with a guid and delete the index after every test run.
This is also the approach NEST itself takes when running integration tests: https://github.com/elastic/elasticsearch-net/blob/develop/src/Tests/Nest.Tests.Integration/IntegrationSetup.cs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With