What is the difference between unit testing and integration testing when it come to web development (where 90-95% of the code relies on a database)? One thing I here all the time is that unit testing should not deal with databases and integration testing should. The issue I have with this is that to me that means the only difference between unit testing and integration testing is the data source and if that is the case, you are testing the same functionality. If the functionality that is tested is the same, why even bother with unit testing and always test against a database?
feedback
|
Integration testing is about testing the integration points between 2 or more systems, this could be a database, it could be a web service.. whatever it is, it is interaction based, i.e. What happened to my component when it calls a stored proc that does xy and z? Has a web service changed its interface? Unit testing deals with a single unit of work. Each unit test should test just one thing that method should do, this is where you stub out the database and any external interfaces or interactions. | |||
feedback
|
http://www.typemock.com/unit-tests-integration-tests Another thing that isn't mentioned above is that it shouldn't rely on any special configuration. Can any developer check out a copy of the source code and run the unit tests? With a database you require each developer to have the same database configuration set up. What if some of the developers don't work with the database normally? | ||||
feedback
|
Unit Testing is all about testing a single component (and thus simpler than integration testing). Unit test is really good to make sure your public interface does not break during bug fixes. Each class (component) is tested in isolation without using any dependencies (dependencies are usually injected and mocked). Thus you are usually able to test 100% of execution paths (by getting your injected dependencies to give you every different kind of result (including errors)). This would be really hard achieve with a real data source as generating the error responses are hard (e.g. DB how do your force DB exception at the correct point in the test). Integration tests is about how the components work together. Here you write test on how systems of components work together. It test to make sure that you have not deprecated any interfaces that are needed. Stuff like that. | |||
feedback
|