Timbo said:
Using OO terminology, I define a unit as a class. How to test that unit
in isolation depends on its dependencies. If it depends on other classes
from within the application, those should be stubbed during unit
testing, otherwise it is integration testing. If you feel the CUT's
dependents are simple enough, you may not feel the need to unit test it,
and will probably just use the production classes instead of stubs, but
that, in my mind, is not unit testing.
Tim
It depends upon how that class came into being, what it does and your
mood at the time.
In TDD we write a test, write the code, refactor.
now we normally start out by creating a class and its method we are
exercising. But after several test,code, refactor cycles we see that our
single class needs further simple refactorings because its really
several classes in one (e.g. a dispatcher type class which creates
instances of different command classes). but we started out with one
class and so far have one test class for it.
At this point we have a choice:
1) Leave the single test class as is - its testing our original class
and n other command classes.
2) Change the test class to test the original class, using fake/mock
Command objects. Then move the testcase methods from the original
testclass into new test classes, one for each Command class.
Here we end up with lots of small test classes, each testing an
individual class.
Both approaches are fine - both are unit tests - thats how they started
out.
For me the point at which a Unit Test stops becoming a unit test, is
when its difficult to setup a test. At this point the test code is
telling us - 'I'm a functional test'.
YMMV
Andrew