|
Re: Are Tests First Class Clients?
|
Posted: Jan 27, 2005 10:39 AM
|
|
> The verify() methods are equivalent to > get methods, in that they expose data for > comparison, so I recommend going one step further: > implement equals() to compare > Merger instances by their current state. This > way, your tests can simply use assertEquals() > to compare expected state with actual state, without > exposing the internals of that state. > Actually, the verify methods don't expose data for comparison. They use the private data and either return quietly or throw a TestFailedException .
I considered the equals approach you suggest, and it is a good suggestion. But the reason I didn't go that way is that I wanted more information passed to TestFailedException than just the contents of the Merger s are different. I want to find out how they are different.
> This might seem strange, since the class name is > Merger . A verb-named class implementing > equals() ? Well, I don't like verb-named > classes, because those are generally procedures, rather > than objects. If procedural code is appropriate here, then > I'd expect a design like this: > MergeResult result = merger.merge(templateName,
> velocityContext);
> Here, result contains the string-based output > along with any metadata describing the rendered page. (If > there is none, then maybe MergeResult is just > String .) > Actually, "Merger" is a noun. It usually means two companies companies joining forces, so it doesn't quite fit here, but it is catchy and distinctive and seems to serve us well in discussions. The verb "merge" is the name of one of its methods.
|
|