All of us know about unit test. But what's a unit?

B

Bill David

A method? A class? A bunch of related classes? A module? An API we
exposed from a module? ...

My opinion is all of them are units for different test requirement.
But my friend doesn't agree. He thinks we should only write unit test
for a single method of a single class. How do you think?
 
T

Tom Anderson

A method? A class? A bunch of related classes? A module? An API we
exposed from a module? ...

My opinion is all of them are units for different test requirement. But
my friend doesn't agree. He thinks we should only write unit test for a
single method of a single class. How do you think?

A unit is the smallest testable part. 'Atom tests' would have been a
better name :).

Yes, you can and must test larger assemblies, and it doesn't hurt to make
this part of your continuous automated testing regime, if the tests run
fast enough. But the point of unit tests is to verify that all the
individual components work properly. A larger-scale test might tell you
that something's broken, but it probably won't tell you what.

At the other end of the scale, there are 'functional' or 'acceptance'
tests, which exercise the whole system, or large parts of it. You need to
have these too, to pick up subtle faults which arise in interactions
between the smaller parts, but they're the kind of thing you run as part
of your integration routine, not immediately after every refactoring, as
you should with unit tests.

tom
 
A

Arne Vajhøj

Bill said:
A method? A class? A bunch of related classes? A module? An API we
exposed from a module? ...

My opinion is all of them are units for different test requirement.
But my friend doesn't agree. He thinks we should only write unit test
for a single method of a single class. How do you think?

A unit *must* be one or more strongly related classes that
seen from other developers can be considered a single entity.

A unit *should preferable* be a single class. But that is
not always possible.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top