Reusing base classes tests?

Hi Karsten,

Hi Holden and thanks for your prompt reply,

I’m not sure what you would need to retest in the subclass since whatever you
tested in the superclass has also been tested in the subclass. I tend to only
test the public interfaces. In my experience tests are not reused, but can
have parts of them extracted and reused, the test itself (the inputs and
assertions) are specific for that individual method - if they are not, do you
have the same method twice or is your design as simple as it ought to be?
Perhaps I don’t understand your example enough, can you provide a scenario?

Base class (B) has an invariant that should always hold for subclasses
(S):

s = S.new
B.parse(s.to_s) == s

but subclasses might implement to_s differently (within a prespecified
structure).

B.parse would check the start of the string supplied to know which
subclass to call parse on. In this design subclasses will need to
register with the B.parse method though so maybe its my design that
is flawed?

Its for messages that should be marshaled and sent over
a network and then “opened” as ruby objects again. I don’t
want to rely on Marshal.dump since the format might change
between different Ruby implementations (or am I wrong?).

Maybe its my design here that is flawed? (If so anyone got
ideas for a better one?)

Regards,

Karsten

···


http://fastmail.fm/ - A no graphics, no pop-ups email service