Andrew Stopford's Weblog

poobah

Sponsors

News

Articles

Family

Old Blogs

VSTS Unit Testing Private Methods

I have been thrashing the unit testing abilities of VSTS lately and something my TL raised has set me thinking. The unit test wizard allows you to create unit tests based on your code (given that TDD requires unit tests first is another point), it allows you to select public, private methods and properties. My TL asked why privates, and its a very valid point. Given that unit testing is about testing all of your code via the public methods and ensuring that your tests run through all your private methods via the depth of your tests is a main stay of unit testing. VSTS includes code coverage tools so you can even check that your achieving this with your tests so why test privates directly, anyone.....

Comments

Peter Ibbotson said:

One potential reason is to execute code paths for invalid states easily (makes checking that an invalid value in a switch does throw an exception). Ideally you shouldn't need to do this but it can be quite useful, particularly for regression testing.

You have to remember that the Unit Test stuff in here isn't just designed for TDD. TDD as a development model is pretty good for some things, but I don't think it's very good at the throw random data at an object kind of testing that good testers do.
# June 3, 2005 6:53 AM

Jerrad Anderson said:

Another good reason to test private methods is that sometime they are class helpers. Methods that are used internally to do some sort of repetitive class task. Testing these method then becomes just as important as testing public methods
# June 3, 2005 10:51 AM

TrackBack said:

Visual Studio Team System


Bill Sheldon from InterKnowlogy has an item in the June 3rd edition of...
# June 4, 2005 9:06 PM

poker games site said:

You are invited to check some relevant information on texas hold em site http://www.allabout-poker.com/texas-hold-em.html
... Thanks!!!
# June 29, 2005 2:24 AM

Unit Test Private Methods in Visual Studio | Emad Ibrahim said:

Pingback from  Unit Test Private Methods in Visual Studio | Emad Ibrahim

# July 9, 2008 1:33 PM