Unit Test vs Integration Test in Web Development [closed] Unit Test vs Integration Test in Web Development [closed] php php

Unit Test vs Integration Test in Web Development [closed]


This is a damn good question, and one that more developers should be asking themselves.

I don't think this only applies to web development, but I think it's a good example to base the discussion on.

When deciding on your testing strategies, the points you raised are very valid.In a commercial world, cost (in terms of time) is likely the most important factor.I always follow some simple rules to keep my testing strategies realistic.

  • Unit test important, unit testable "libs" (Auth, Billing, Service Abstractions, etc)
  • Unit test models, assuming you have any, where possible (and it really should be possible!)
  • Integration test important endpoints of your application (totally depends on the app)

Once you've got these three points nailed, given your cost constraints you could potentially continue to test anything else that makes sense, in the way that makes sense.

Unit testing and integration testing aren't mutually exclusive, and unless you're building a beautifully unit testable library, you should do both.


The short answer is yes. Unit tests are valuable as are integration tests.Personally I'm not that good at doing TDD, but what I've noticed is that it greatly improves design because I have to think first and then code.That's invaluable, at least, for me but it also takes a lot of getting used to.This, I think, is the main reason to why it is so widely misunderstood.

Let's go through your points:

No Algorithms (but what you mean is few):

Well as stated in the comments, that depends on the application. This actually has nothing to do with TDD. Having few algorithms is not an argument to not test them. You may have several different cases with lots of different states. Wouldn't it be nice to know that they work as intended?

Cost

Sure it will cost, and if it is a small project, you might not get any value from TDD if you or your developers are new to it. Then again a small project might be just the thing to get started with it, so you are up to speed for the next, bigger project. This is a calculation you must do yourself. We are programmers, not economists.

Integration Test

Test that too!

Integration test says "something is broken" but doesn't say where

I'm sorry but I don't understand this one.

Hard to maintain

If it is hard to maintain you're doing it wrong. Write the test first, change the test before the implementation, when changing the code. Failing tests during development is a must for TDD. Actually don't quote me on that one, that is just my limited understanding of TDD.

I find this to be a very nice quote about unit-tests

Unit tests should be prescriptive, not descriptive. In other words, unit tests should define what your code is supposed to do, not illustrate after the fact what your code does.

What it boils down to is that integration tests and unit testing are two different things. TDD is a methodology for development, integration tests is more a validation of the application working as expected from a users vantage point.

EditThe community wiki says this about integration testing:

In an integration test, all input modules are modules that have already been unit tested. These modules are grouped in larger aggregates and integration tests (defined in an integration test plan) are applied to those aggregates. After a successful integration test, the integrated system is ready for system testing.

So actually my understanding of what integration testing is was wrong from the start, but I don't think my answer is too far off except for the last paragraph.


Integration test takes more time to execute compared to unit test.

"...all about integration there are always multiple dependencies" -> if you are coding on a dependent unit without completing the others, then you can't do integration test yet. If you want to make sure your code is working at this point, you you can do unit testing.

If each members of your team is developing their own dependent unit, they can't do integration test yet because the required units are still being developed by others. But at least they can make sure their code is working if they perform unit testing before committing to repository.