[2 ⅛s] Testing Private Methods/Member Variables

James Newkirk asks if one should test private methods using Unit Tests.

I immediately thought “definately!”, but then I thought about it a little again.

I think that this should be allowed but should be recommended only for methods that have a logical function of their own that could be isolated.

For instance, take this method:

private bool IsTriangle(int side1, int side2, int side3)
// TODO: Implement ;)

This private method gets 3 integer parameters and calculates if a triangle could be formed from the three integers when used as its sides.
Even though this method is private, I would definately like to test it individually as well, to see that all is well with it.
There’s no real chance that I would remove this method when maintaining the application, but even if there was, I still would love to have something written down that tests it.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s