I'm trying to better understand unit tests and integration tests. I understand unit tests should be in isolation and their dependencies should be mocked. But I'm slightly unclear on the best approach to assert that each class unit tested integrates with it's dependencies.
Here is an example:
I have a class called ElasticDocumentFeeder which basically calls elastic's httpHTTP end point and indexes a document. There's a method called AddDocument(Document document, logger)AddDocument(Document document, logger)
This method simply calls the http endpoint using the .net httpHTTP client with a putPUT to index a document, if. If the statusresponse code is anything other than a 200, an error is logged.
I want to write a test that asserts that if a document is rejected by elastic, the error is logged.
I've managed to do this using NUnit and Moq and I'm able to assert the invocation on the logger.
However what I want to know is that even though I'm testing this class it does have a dependency which is it expects elastic to be running on localhost:9200 so would this be considered a unit test or an integration test?
I know I can abstract the http endpoint so that I could mock an exception that is thrown by elastic. Do you think this would be the more correct approach and as a result it would truly be a unit test? Or is it fine to have something like elastic running with a unit test with regard to being pragmatic.
What I want to know is: even though I'm testing this class, it does have a dependency. It expects elastic to be running on localhost:9200. So would this be considered a unit test or an integration test?
Therefore my questionI know I can abstract the HTTP endpoint so that I could mock an exception that is shouldthrown by elastic. Do you think this would be the more correct approach and as a result it would truly be a unit test? Or is it fine to have something like elastic running with a unit test with regard to being pragmatic?
Should I have an end to end-to-end integration test which would cover everything i? I.e. a message would be picked up from rabbit, then a call would be made to instantiate MessageProcessor then ElasticDocumentFeeder etc should.? Should I test each class individually against all it'sits dependencies with regard to integration tests? Or is this all over killoverkill, as I would then need an instance of rabbit and elasticsearch?