<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Test Driven Development: Testing Private Methods Using Aspect Oriented Programming</title>
	<atom:link href="http://www.khussein.com/tdd-testing-private-methods-using-aop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/</link>
	<description>Thoughts, Hacks, Coding, Creativity, and Fun.</description>
	<lastBuildDate>Tue, 07 Sep 2010 15:36:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Nick</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-3481</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Tue, 07 Sep 2010 15:36:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-3481</guid>
		<description>Check out Powermock. It is a testing library that allows you to call private methods directly. You can do a lot of stuff such as set/get private memebers without setter/getters.</description>
		<content:encoded><![CDATA[<p>Check out Powermock. It is a testing library that allows you to call private methods directly. You can do a lot of stuff such as set/get private memebers without setter/getters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JNovice</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-3480</link>
		<dc:creator>JNovice</dc:creator>
		<pubDate>Tue, 31 Aug 2010 13:42:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-3480</guid>
		<description>Hi,

Nice post and great discussion. While I have been using reflection to great effect for testing private methods so far, I have hit a road-block with testing private methods when the source code undergoes obfuscation. I tried this method and it works really well for me. While I understand that testing private methods is like breaking encapsulation and not in keeping with the design, there are some places where you would want to do this.

Thanks for the nice article</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Nice post and great discussion. While I have been using reflection to great effect for testing private methods so far, I have hit a road-block with testing private methods when the source code undergoes obfuscation. I tried this method and it works really well for me. While I understand that testing private methods is like breaking encapsulation and not in keeping with the design, there are some places where you would want to do this.</p>
<p>Thanks for the nice article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Khaled Hussein</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-588</link>
		<dc:creator>Khaled Hussein</dc:creator>
		<pubDate>Fri, 03 Apr 2009 18:47:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-588</guid>
		<description>Tomek,
Thanks for you comment. I agree with you that there are plenty of solutions (hacks) to this problem. So, you can think of this one as yet another solution that leverages relatively new technologies such as Aspect Oriented Programming. 

As comparing it to reflection, I don&#039;t think that reflection is any simpler. However, I have to say that reflection gives you one of the same advantages which is testing private methods without adding any code to your code base. Yet in both cases, tests will be clear to understand and so forth -- maybe not as clear as other approaches. 

Side note: I don&#039;t think that because there aren&#039;t that many developers that know AspectJ, we should ignore what AspectJ can do for us :). 

I am just sharing my basic knowledge and some of my thought.</description>
		<content:encoded><![CDATA[<p>Tomek,<br />
Thanks for you comment. I agree with you that there are plenty of solutions (hacks) to this problem. So, you can think of this one as yet another solution that leverages relatively new technologies such as Aspect Oriented Programming. </p>
<p>As comparing it to reflection, I don&#8217;t think that reflection is any simpler. However, I have to say that reflection gives you one of the same advantages which is testing private methods without adding any code to your code base. Yet in both cases, tests will be clear to understand and so forth &#8212; maybe not as clear as other approaches. </p>
<p>Side note: I don&#8217;t think that because there aren&#8217;t that many developers that know AspectJ, we should ignore what AspectJ can do for us <img src='http://www.khussein.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>I am just sharing my basic knowledge and some of my thought.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: online gambling history</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-511</link>
		<dc:creator>online gambling history</dc:creator>
		<pubDate>Sat, 28 Mar 2009 07:08:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-511</guid>
		<description>How to test private methods? This question comes up a lot but I just don’t get it. What test drove you to write a private method in the first place? In my experience private methods pop out of the re factoring stage and are adequately covered by the existing tests. Of course at some point in the future a test I write might need the functionality in that private method, at that point it will get hoisted in to the public interface of some class and have appropriate tests.The question is what private methods to test? I have had a lot of answers to this question and all of them boil to that we should test private methods that have more than one path of execution and we need to test different paths, private methods that are complex enough not to be covered by one test scenario, and private methods that may or may not be executed by public ones. I normally only end up with private methods that are there for code clarity/duplication removal reasons. These are exercised perfectly by the tests that test the behavior of the class under test. All others tend to migrate into the public interface of some other class and become easy to test..I am hoping the same best work from you in the future as well.In fact your creative writing abilities has inspired me to start my own word press blog now. Really the blogging is spreading its wings rapidly.Your write up is a fin example of it.</description>
		<content:encoded><![CDATA[<p>How to test private methods? This question comes up a lot but I just don’t get it. What test drove you to write a private method in the first place? In my experience private methods pop out of the re factoring stage and are adequately covered by the existing tests. Of course at some point in the future a test I write might need the functionality in that private method, at that point it will get hoisted in to the public interface of some class and have appropriate tests.The question is what private methods to test? I have had a lot of answers to this question and all of them boil to that we should test private methods that have more than one path of execution and we need to test different paths, private methods that are complex enough not to be covered by one test scenario, and private methods that may or may not be executed by public ones. I normally only end up with private methods that are there for code clarity/duplication removal reasons. These are exercised perfectly by the tests that test the behavior of the class under test. All others tend to migrate into the public interface of some other class and become easy to test..I am hoping the same best work from you in the future as well.In fact your creative writing abilities has inspired me to start my own word press blog now. Really the blogging is spreading its wings rapidly.Your write up is a fin example of it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomek</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-226</link>
		<dc:creator>Tomek</dc:creator>
		<pubDate>Mon, 01 Dec 2008 21:45:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-226</guid>
		<description>Khaled, the web is full of descriptions on how to test private methods in java, and the solutions (e.g. reflection API) are much simpler than using AspectJ (how many developers know AspectJ ? how many will understand your tests ? IMHO simplicity of test code is crucial), so why bother with such a big cannon here ? I don&#039;t understand why you propose such a weird solution with no real advantage over other existing ones.

Tomek</description>
		<content:encoded><![CDATA[<p>Khaled, the web is full of descriptions on how to test private methods in java, and the solutions (e.g. reflection API) are much simpler than using AspectJ (how many developers know AspectJ ? how many will understand your tests ? IMHO simplicity of test code is crucial), so why bother with such a big cannon here ? I don&#8217;t understand why you propose such a weird solution with no real advantage over other existing ones.</p>
<p>Tomek</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: seo blog</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-63</link>
		<dc:creator>seo blog</dc:creator>
		<pubDate>Tue, 28 Oct 2008 13:40:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-63</guid>
		<description>This is a really interesting blog post,I have added your blog to my bookmarks I really like it,keep up the good work!</description>
		<content:encoded><![CDATA[<p>This is a really interesting blog post,I have added your blog to my bookmarks I really like it,keep up the good work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Genisio</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-61</link>
		<dc:creator>Brian Genisio</dc:creator>
		<pubDate>Wed, 22 Oct 2008 02:01:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-61</guid>
		<description>I agree with the anti-private testing camp.  There are ways in .NET to use reflection to gain access to privates which are pretty slick.  In almost all cases (except for cases where driving the GUI is involved), I consider this to be bad practice.

If there is code in a private that a public method cannot hit via a unit test, it is probably dead code and should be removed.  If that code is necessary, but you can&#039;t test it, then you probably need to re-think your design.

Unit tests, in my opinion, are used to test and hold up the design of the code you are testing.  Your assumptions and requirements for the unit are baked directly into the tests.  They test behavior and privates do not expose behavior... publics do.  In TDD, privates are just refactorings of the public behavior.

I have been doing TDD for over a year now, and I have been successful in writing full test suites for units without testing privates.  

I agree, it is a matter of philosophy...  a debate that needs to keep happening.  Without it, we will remain stagnant.

Cheers!</description>
		<content:encoded><![CDATA[<p>I agree with the anti-private testing camp.  There are ways in .NET to use reflection to gain access to privates which are pretty slick.  In almost all cases (except for cases where driving the GUI is involved), I consider this to be bad practice.</p>
<p>If there is code in a private that a public method cannot hit via a unit test, it is probably dead code and should be removed.  If that code is necessary, but you can&#8217;t test it, then you probably need to re-think your design.</p>
<p>Unit tests, in my opinion, are used to test and hold up the design of the code you are testing.  Your assumptions and requirements for the unit are baked directly into the tests.  They test behavior and privates do not expose behavior&#8230; publics do.  In TDD, privates are just refactorings of the public behavior.</p>
<p>I have been doing TDD for over a year now, and I have been successful in writing full test suites for units without testing privates.  </p>
<p>I agree, it is a matter of philosophy&#8230;  a debate that needs to keep happening.  Without it, we will remain stagnant.</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-52</link>
		<dc:creator>Jacob</dc:creator>
		<pubDate>Fri, 03 Oct 2008 13:23:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-52</guid>
		<description>In Java at least, there are multiple implementations you can find of a PrivateAccessor class that can modify private fields and invoke private methods on an object.  

The biggest issue I have is that you normally don&#039;t test drive private methods at all.  You are testing the behavior of your object and that behavior is defined by the public parts of that object.  Basically, you write a test (red), you implement it (green), and then you remove duplication or increase clarity by pulling parts of your public methods out to private ones (refactor).</description>
		<content:encoded><![CDATA[<p>In Java at least, there are multiple implementations you can find of a PrivateAccessor class that can modify private fields and invoke private methods on an object.  </p>
<p>The biggest issue I have is that you normally don&#8217;t test drive private methods at all.  You are testing the behavior of your object and that behavior is defined by the public parts of that object.  Basically, you write a test (red), you implement it (green), and then you remove duplication or increase clarity by pulling parts of your public methods out to private ones (refactor).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clark</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-51</link>
		<dc:creator>Clark</dc:creator>
		<pubDate>Thu, 02 Oct 2008 14:10:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-51</guid>
		<description>I think what both Michael Feathers and I are trying to say is that testing a private method is only treating a symptom of the real problem, we should be fixing the real problem i.e. the lack of cohesion in the design.</description>
		<content:encoded><![CDATA[<p>I think what both Michael Feathers and I are trying to say is that testing a private method is only treating a symptom of the real problem, we should be fixing the real problem i.e. the lack of cohesion in the design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Khaled Hussein</title>
		<link>http://www.khussein.com/tdd-testing-private-methods-using-aop/comment-page-1/#comment-50</link>
		<dc:creator>Khaled Hussein</dc:creator>
		<pubDate>Thu, 02 Oct 2008 13:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.khussein.com/wordpress/?p=38#comment-50</guid>
		<description>Martin,

As for Michael Feather&#039;s article, I think it is interesting. However, I think that &quot;your design will improve if you aim for testability&quot; is something that we all know and agree upon once you start using TDD ;). Right? The only problem is that your design improves over longer periods of time, which is debatable and out of scope. The scope of my post is to show you a new tool to use for testing private method if you need to.

I&#039;d like also to expand our vision here to multiple purposes behind unit testing. For example, code coverage in which you might need to unit test specific paths in private methods. 

Note: I don&#039;t regret things easily (if ever) ;). We learn from our experiences and from nice people like you sharing their thoughts :).</description>
		<content:encoded><![CDATA[<p>Martin,</p>
<p>As for Michael Feather&#8217;s article, I think it is interesting. However, I think that &#8220;your design will improve if you aim for testability&#8221; is something that we all know and agree upon once you start using TDD <img src='http://www.khussein.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Right? The only problem is that your design improves over longer periods of time, which is debatable and out of scope. The scope of my post is to show you a new tool to use for testing private method if you need to.</p>
<p>I&#8217;d like also to expand our vision here to multiple purposes behind unit testing. For example, code coverage in which you might need to unit test specific paths in private methods. </p>
<p>Note: I don&#8217;t regret things easily (if ever) <img src='http://www.khussein.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . We learn from our experiences and from nice people like you sharing their thoughts <img src='http://www.khussein.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
</channel>
</rss>
