Skip to main content
Non-vague title; cleaned up grammar and run-on sentences.
Source Link

Would this be considered How should I structure an integration or unitautomated test with a dependency on an HTTP endpoint?

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.

  1. 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?

  2. 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?

Would this be considered an integration or unit test?

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 http end point and indexes a document. There's a method called AddDocument(Document document, logger)

This method simply calls the http endpoint using the .net http client with a put to index a document, if the status 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.

  1. 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?

  2. 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.

Therefore my question is should I have an end to end integration test which would cover everything i.e. a message would be picked up from rabbit then a call would be made to instantiate MessageProcessor then ElasticDocumentFeeder etc should I test each class individually against all it's dependencies with regard to integration tests? Or is this all over kill as I would then need an instance of rabbit and elasticsearch?

How should I structure an automated test with a dependency on an HTTP endpoint?

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 HTTP end point and indexes a document. There's a method called AddDocument(Document document, logger)

This method simply calls the endpoint using the .net HTTP client with a PUT to index a document. If the response 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.

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?

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?

Should I have an end-to-end integration test which would cover everything? I.e. a message would be picked up from rabbit, then a call would be made to instantiate MessageProcessor then ElasticDocumentFeeder etc.? Should I test each class individually against all its dependencies with regard to integration tests? Or is this all overkill, as I would then need an instance of rabbit and elasticsearch?

Source Link

Would this be considered an integration or unit test?

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 http end point and indexes a document. There's a method called AddDocument(Document document, logger)

This method simply calls the http endpoint using the .net http client with a put to index a document, if the status 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.

  1. 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?

  2. 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.

Therefore my question is should I have an end to end integration test which would cover everything i.e. a message would be picked up from rabbit then a call would be made to instantiate MessageProcessor then ElasticDocumentFeeder etc should I test each class individually against all it's dependencies with regard to integration tests? Or is this all over kill as I would then need an instance of rabbit and elasticsearch?