[Mono-list] Mono test suite

Nick Drochak ndrochak@gol.com
Thu, 23 May 2002 11:03:32 +0900


| -----Original Message-----
| From: mono-list-admin@ximian.com [mailto:mono-list-admin@ximian.com]On
| Behalf Of Saajan Chana
| Sent: Thursday, May 23, 2002 1:50 AM
| To: mono-list@ximian.com
| Subject: [Mono-list] Mono test suite
|
|
| Should I test protected as well as public methods?  (e.g. by deriving a
| front-end class from the class I am testing and allowing my test class to
| call the protected methods).
|

I believe, in general, only the public methods (and properties) need be
tested with unit tests.

First of all, to test the non-public ones would require access to them. And
they are, by definition, not accessible by the unit test because they are
not public. You would end up adding "for testing only" public methods to get
at them, which just ends up cluttering the sources.  Or you might do as you
suggest and subclass to get at it.  Both of these things just don't "feel
right".

Secondly, the public interface of a class tends to be less volatile.  It
changes less often, in other words.  This makes it easier to keep your tests
up to date.

Also, non-public methods will be used by the public ones eventually, and
therefore will be tested, albeit somewhat indirectly. Those that are never
reached by a public access point are unneeded anyway.

See http://c2.com/cgi/wiki?UnitTests for more info (and debate).  Search for
"private implementation" on the page and read from there.

HTH,
Nick D.