[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [OT] Unit Tests and Encapsulation

Mark Wilson

9/4/2003 3:05:00 AM

I know nothing about bezier curves or drawing programs, so this may not
be helpful. I'm also not an expert on unit testing, so others may have
more useful input. Anyway...

On Wednesday, September 3, 2003, at 10:42 PM, Scott Thompson wrote:

> [snip]
> The problem is that once you have constructed the path, there is no
> way in the public interface (at least not at the moment) for you to go
> back and examine the points in the path.
> [snip]

I think that for unit testing purposes you don't care whether the
interface is public or private, you test it anyway. I don't know if
Test::Unit has a mechanism for gaining access to private methods or if
you have to remove privacy for the duration of the tests.

> One means of making a more meaningful Unit Test would be to allow the
> unit test to access the points of the curve (the control polygon for
> fellow math geeks) and verify that the resulting polygon matches the
> one that the drawing commands should produce. Adding the routine to
> examine the control polygon, however, would be a violation of the
> encapsulation (or more to the point the current design of the class
> which states that the control polygon not be available) of the
> BezierContour class.

I don't know how your class works, but if it's monolithic (there is no
interface to the control polygon outside of the object) I think your
choices are (1) to temporarily add an interface for testing purposes or
(2) decouple the elements of the class in order to expose an interface
or (3) write the test to compare the produced object (i.e., by
comparing a previously prepared file with the specified curve to a file
produced by invoking the object with test input data). The last test is
a big leap because it looks at the final product and not intermediate
functionality.

> [snip]

> The question I have, however, is one of style. Is this kind of class
> extension often done in Unit Testing or is it more likely that the
> Unit Test would only test the common public interface for the class.

I think the most usual approach is to test all interfaces (public and,
at least initially during development, private) and to decouple
functional elements of objects as much as possible during the
development process. Most important though, is to write a test first
and then implement it and then write another test and so on. If one
writes the test first, concerns about encapsulation usually evaporate
because the only concern in writing the test case is the interface.

> [snip]

Regards,

Mark