<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx</link><description>I&amp;#8217;m heading off into the deep end here. If you want to come with me, make sure you&amp;#8217;re wearing your SCUBA gear. One of the first questions that come up in TDD with NUnit is &amp;#8220; How do I test private methods?&amp;#8221; Usually the answer looks</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>RE: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#153986</link><pubDate>Sat, 12 Jun 2004 01:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:153986</guid><dc:creator>Klaus Probst [MVP]</dc:creator><description>But the question is bogus to begin with. Private methods should exist only in support of exposed entry points and public aspects or facets in your components. There should be *absolutely* no requirement that involves even remotely trying to get to them. A good testing strategy should cover them completely, since they'll be excercised as the public interface is put through its paces.</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#154007</link><pubDate>Sat, 12 Jun 2004 02:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154007</guid><dc:creator>Karl</dc:creator><description>aside from the debate about whether private methods should be tested, any thoughts on this solution for testing them:&lt;br&gt;&lt;br&gt;&lt;br&gt;#if UNIT_TEST&lt;br&gt;      public static ArrayList GetCategories_UnitTest (string filename){&lt;br&gt;         return GetCategories(filename);&lt;br&gt;      }&lt;br&gt;#endif &lt;br&gt;      private static ArrayList GetCategories (string filename){&lt;br&gt;         //implementation&lt;br&gt;      }</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#154011</link><pubDate>Sat, 12 Jun 2004 03:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154011</guid><dc:creator>Jonathan Cogley</dc:creator><description>I get asked this question frequently when presenting on TDD - in fact I even have a slide on it!  I tend to agree with what Klaus said.  Don't think about testing every method, rather focus on testing features.  Remember that TDD comes from XP where business value is key ... therefore each test should be focusing on an aspect of business value and all code supporting it will then have full coverage.&lt;br&gt;&lt;br&gt;Your &amp;quot;Extract Class&amp;quot; idea is interesting but your design should be dictated by refactoring after getting to green rather than to test each method.  Think &amp;quot;tests == features&amp;quot;!&lt;br&gt;&lt;br&gt;</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#154110</link><pubDate>Sat, 12 Jun 2004 09:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154110</guid><dc:creator>Adi Robinson</dc:creator><description>I your idea because it's so controversial, from an O-O perspective.  On the extract class refactoring I have to say that object domain pollution and loss of cohesiveness in the abtractions being modeled are good reasons to refute it...however command pattern and the strategy pattern represent approaches where externalising a feature can have some design benefits.&lt;br&gt;&lt;br&gt;However, from a TDD perspective I think we have to decide on one of two approaches.  &lt;br&gt;&lt;br&gt;1) Do I only test my public interface - and thereby if my public interfaces honours it's contract the discrete private implementations MUST work (at least within the bounds of the values passed to them from the public interface, AND assuming exhaustive public interface testing)&lt;br&gt;&lt;br&gt;or &lt;br&gt;&lt;br&gt;2) Do we test private methods because as stand alone functional units they have pre and post invariants I want to force to be correct?&lt;br&gt;&lt;br&gt;You could argue, that if you've done proper TDD, then your private methods emerged as extract method refactorings once duplication occurred and so hence where tested as part of that design evolution?  And, given that you would clearly re-run your old tests on the now multi-method-provided implementation of a once contiguous code block means that if you get the green light you are indeed testing your private methods.&lt;br&gt;&lt;br&gt;I'm not entirely sure either way.</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#154204</link><pubDate>Sat, 12 Jun 2004 15:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154204</guid><dc:creator>Nicole Calinoiu</dc:creator><description>There's another potential consequence that you didn't mention: impact on the performance/security trade-off.&lt;br&gt;&lt;br&gt;Ignoring for the moment the potential impact of reflection into low accessibility members, a private method sits inside the input boundary of its class.  For most private methods, very little parameter validation is necessary since this has already been performed elsewhere in the class or the values were safely generated inside the same class.  However, if the method becomes a public method of another class, all parameters must be re-validated completely since their values are supplied from outside the input boundary of the new class.  In general, a performance decline should be expected, particularly if one is calling the method from within a loop.&lt;br&gt;&lt;br&gt;Obviously, it is possible for callers outside a given class to be considered trustworthy, so the above is a bit of an over-simplification.  However, the general problem applies any time you open a low accessibility member to more callers.&lt;br&gt;&lt;br&gt;That said, if reflection into low accessibility members is a concern, the method is probably already written as if it were public, so the performance impact of the change isn't likely to be a consideration.</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#154222</link><pubDate>Sat, 12 Jun 2004 15:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154222</guid><dc:creator>Michael Swanson</dc:creator><description>And it's &amp;quot;jibe&amp;quot;, not &amp;quot;jive&amp;quot;. :)</description></item><item><title>The most extreme thing that could possibly work</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#154920</link><pubDate>Mon, 14 Jun 2004 07:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154920</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#154955</link><pubDate>Mon, 14 Jun 2004 06:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:154955</guid><dc:creator>Mikhail Arkhipov (MSFT)</dc:creator><description>Programming reflects real life. 'No private methods' is like 'no private life' :-) If someone is calling you and asking for something you have right to talk to your significant other before answering. I believe every object has right to the private life as well :-).&lt;br&gt;&lt;br&gt;Seariusly, exposing everything increases test matrix. If before a private method A was only supposed to be called from B now anyone can call A at any time. </description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#155302</link><pubDate>Mon, 14 Jun 2004 18:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155302</guid><dc:creator>jaybaz [MS]</dc:creator><description>Michael: You're right!  A goggle search on &amp;quot;define: jive&amp;quot; didn't mention compatibility.  A search on &amp;quot;define: jibe&amp;quot; was mostly about sailing (yay) but also had this entry at the very bottom.&lt;br&gt;&lt;br&gt;&amp;quot;be compatible, similar or consistent; coincide in their characteristics&amp;quot;&lt;br&gt;&lt;br&gt;&lt;a target="_new" href="http://www.cogsci.princeton.edu/cgi-bin/webwn?stage=1&amp;amp;word=jibe"&gt;http://www.cogsci.princeton.edu/cgi-bin/webwn?stage=1&amp;amp;word=jibe&lt;/a&gt;</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#155693</link><pubDate>Tue, 15 Jun 2004 01:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155693</guid><dc:creator>Darren Oakey</dc:creator><description>I know you are just throwing up a question, what about &amp;quot;no private methods&amp;quot; - but I'd like to squash it :)&lt;br&gt;&lt;br&gt;I always make an attempt to make as much of my underlying implementation as private as is theoretically possible, and think that's a good thing..&lt;br&gt;&lt;br&gt;I think almost all the advances in modern languages and concepts come down to information hiding - or, to look at it another way - &amp;quot;simplifying&amp;quot;. &lt;br&gt;&lt;br&gt;In the bad old days, I had to understand every bit of making an ftp connection, listening on a port, worrying about synchronisation, etc etc etc.&lt;br&gt;&lt;br&gt;Now I just go &amp;quot;new FtpConnection( server)&amp;quot;, and myConnection.GetFile().   Over time, with many people using the same library, in the same way, we find the bugs - it gets more and more robust - deals with more and more situations, and the code gradually improves. &lt;br&gt;&lt;br&gt;This occurs because we have a tiny interface as wrapper to a large amount of functionality.  Even though it may sometimes be restrictive, people always use it the same way, because that's the only choice they have.&lt;br&gt;&lt;br&gt;And that's how software improves.  Expose all the underlying interface, allow people to change things, and we've just stepped back 20 years into unproductiveness...   &lt;br&gt;&lt;br&gt;Anyone who has programmed for a long time knows that Limitations = productivity.  (Which is why, as someone who's experienced in everything from asm to vba, I'm more likely to write a quick program as a perl script than a beautiful c++ structure - because it'll take me 1/10th the time, and be 100% stable)&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#155730</link><pubDate>Tue, 15 Jun 2004 03:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155730</guid><dc:creator>Travis</dc:creator><description>One positive side effect might be amazing code reusability.</description></item><item><title>Trackback</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#155736</link><pubDate>Tue, 15 Jun 2004 03:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155736</guid><dc:creator>Travis</dc:creator><description>Trackback &lt;a target="_new" href="http://travis.pettijohn.com/blog/comments.php?entry=98"&gt;http://travis.pettijohn.com/blog/comments.php?entry=98&lt;/a&gt;</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#155744</link><pubDate>Tue, 15 Jun 2004 04:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155744</guid><dc:creator>jaybaz [MS]</dc:creator><description>Travis: I hope so.  Let's try it &amp;amp; see.</description></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#155746</link><pubDate>Tue, 15 Jun 2004 04:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155746</guid><dc:creator>jaybaz [MS]</dc:creator><description>Darrel: I think your concern sounds valid. But I hope that the external interface doesn't charge, so  things work out ok</description></item><item><title>re: Testing Private Methods/Member Variables - Should you or shouldn't you</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#157713</link><pubDate>Thu, 17 Jun 2004 03:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:157713</guid><dc:creator>James Newkirk's Blog</dc:creator><description /></item><item><title>re: Testing Private Methods/Member Variables - Should you or shouldn't you</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#157720</link><pubDate>Thu, 17 Jun 2004 04:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:157720</guid><dc:creator>James Newkirk's Blog</dc:creator><description /></item><item><title>re: No private methods</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#158229</link><pubDate>Thu, 17 Jun 2004 15:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:158229</guid><dc:creator>Iain</dc:creator><description>I think it's kind of self-evident that the private methods should be tested, because unit testing seems to me to be about testing the smallest testable pieces, as opposed to testing generally, which seems to be about testing all the big pieces.&lt;br&gt;&lt;br&gt;This makes it a question of mechanics. The really obvious solution is to have a compiler option that makes the compiler spit out reflection-based invocation code for private functions, so you just write your tests for private members like you do for everything else and pass the violate-encapsulation switch to the compiler, or somehow indicate it otherwise. &lt;br&gt;&lt;br&gt;I might have to try implementing this with the mono c# compiler.&lt;br&gt;&lt;br&gt;It would be possible to just write the reflection invocations for private members yourself, but I think that's just going to make the tests harder to read by a large enough margin that it's going to be a pain.&lt;br&gt;&lt;br&gt;The violate-encapsulation would be subject to abuse, but I can't see it being any worse then the ability to reflect on and therefore invoke private methods when in full trust already is.</description></item><item><title>Jay Bazuzi</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#163946</link><pubDate>Wed, 23 Jun 2004 21:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:163946</guid><dc:creator>public MattBerther : ISerializable</dc:creator><description>One of my favorite bloggers as of late is Jay Bazuzi (rss), who works on the Visual C# IDE team at Microsoft. Give him a read; he's got some posts that are sure to melt your brain, such as &amp;quot;no...</description></item><item><title>Refactoring the C# Express Starter Kit</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#217416</link><pubDate>Fri, 20 Aug 2004 01:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:217416</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>is private method an antipattern &amp;laquo; monkey island</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#6995295</link><pubDate>Sat, 05 Jan 2008 22:30:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6995295</guid><dc:creator>is private method an antipattern « monkey island</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://szczepiq.wordpress.com/2008/01/05/private-method-antipattern/"&gt;http://szczepiq.wordpress.com/2008/01/05/private-method-antipattern/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> jaybaz MS WebLog No private methods | Cellulite Creams</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#9720411</link><pubDate>Wed, 10 Jun 2009 04:26:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9720411</guid><dc:creator> jaybaz MS WebLog No private methods | Cellulite Creams</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://cellulitecreamsite.info/story.php?id=9021"&gt;http://cellulitecreamsite.info/story.php?id=9021&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> jaybaz MS WebLog No private methods | Quick Diets</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/06/11/153978.aspx#9745194</link><pubDate>Sat, 13 Jun 2009 16:53:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9745194</guid><dc:creator> jaybaz MS WebLog No private methods | Quick Diets</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://quickdietsite.info/story.php?id=1309"&gt;http://quickdietsite.info/story.php?id=1309&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>