Reputation: 1533
We recently started TDD approach in our .NET project and we have done good unit testing so far but we are stuck with the question of integration and end to end tests. Say I have three objects whose constructors are as following
constructor(kafka, sql, filesystem); // MOQ all the three
constructor(mongo, webservice, kafka); // MOQ all the three
constructor(googlemaps, sql); // MOQ all the two
Here we have 6 external components to be integrated into our application. We can do unit testing for the three objects by mocking all their dependencies in constructor injection and We can also do end to end testing by having real time set up for all the 6 external components.
My question is how do we deal with integration testing? does Integration testing deal with object testing? I believe unit testing deals with object testing, so integration must deal with external component testing. If we want to write integrate testing, How do I go with?
// Setup kafka real and other objects must still be mocked
constructor(kafka, sql, filesystem); MOQ sql, filesystem but kafka is real
constructor(mongo, webservice, kafka); MOQ mongo, webservice but kafka is real
constructor(googlemaps, sql); MOQ all the two
Write tests by making kafka component as real setup and all other objects as mocked. If we go this way, we end up with repetitive code similar to Unit test but instead of mock objects, we typically end up with real environment setup but the test cases will still be same right?
Can we just have unit tests and end to end tests only? because end to end test does integration test for all objects at once. If end to end tests does all the real time objects testing then why does we still do integration tests? What are some best practices for doing integration tests. When we should we go with doing integration tests. Any help is greatly appreciated.
Upvotes: 1
Views: 6605
Reputation: 1937
If you want to write this tests you need at least to understand why you are writing them. What problems they are going to solve for you. And what is the downside of each kind of tests.
First, some people call End To End integration test, what Martin Fowler in a recent blog call Broad Integration Tests. This tests are more or less like a black box test, useful to some user acceptance scenarios, not easy to maintain and it's hard to conclude what is wrong from a failing test. And from my experience few are useful more are a pain (Mike Cohn pyramid of test could be useful concept here).
In the other hand there is integration tests which verify that the integration with one external service is working, he call that narrow integration tests.
Upvotes: 4