Preslav Rachev
Preslav Rachev

Reputation: 4003

Stuck on a unit testing dilemma

A few noob questions about unit testing.

Let's say I have a class, for every method of which I write a bunch of unit tests.

What happens when I decide to change the design so that this class shouldn't exist anymore, but its functionality should be mixed among other classes? Then all the unit tests become obsolete, right? There is nothing we can do about it.

Then, if we change the design quite often, as it occurs in practice, we should basically write the same tests over and over again. How do we avoid that?

One could avoid this by unit testing only the stone-hard classes, which never change, and for all the rest rely on blackboxed integration testing, but is this the right approach?

Upvotes: 1

Views: 83

Answers (2)

vc 74
vc 74

Reputation: 38179

You might create a facade which interface does not change whilst the implementation can change to follow your class's specs.

But in this case, why not adopt the facade's interface for the class itself?

Upvotes: 0

Shamim Hafiz - MSFT
Shamim Hafiz - MSFT

Reputation: 22094

First of all a good design based on solid requirements shouldn't require major changes to the Class.

In the event you need to frequently change and you still want to adopt Unit Testing, you have no other option but to take the harder way of unit testing every time you make a change. No exception to that.

Upvotes: 3

Related Questions