<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Emad Ibrahim - Latest Comments in Unit Test Private Methods in Visual Studio</title><link>http://emadibrahim.disqus.com/</link><description></description><atom:link href="https://emadibrahim.disqus.com/unit_test_private_methods_in_visual_studio/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 24 Mar 2010 14:27:59 -0000</lastBuildDate><item><title>Re: Unit Test Private Methods in Visual Studio</title><link>http://www.emadibrahim.com/2008/07/09/unit-test-private-methods-in-visual-studio/#comment-41411149</link><description>&lt;p&gt;lifesaver!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">jeffrod</dc:creator><pubDate>Wed, 24 Mar 2010 14:27:59 -0000</pubDate></item><item><title>Re: Unit Test Private Methods in Visual Studio</title><link>http://www.emadibrahim.com/2008/07/09/unit-test-private-methods-in-visual-studio/#comment-21473852</link><description>&lt;p&gt;That's a pretty good idea except for the  fact that it "pollutes" the  &lt;br&gt;code.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emad</dc:creator><pubDate>Sat, 31 Oct 2009 13:24:48 -0000</pubDate></item><item><title>Re: Unit Test Private Methods in Visual Studio</title><link>http://www.emadibrahim.com/2008/07/09/unit-test-private-methods-in-visual-studio/#comment-21460583</link><description>&lt;p&gt;The downside to using PrivateObject is that it is a bit painful to maintain, since signature changes are not caught at compile-time, but instead caught at test-time.  Refactorings that change method signatures tend to catch all the compile-time stuff, but then leave test code broken, and it is tougher to fix.&lt;/p&gt;&lt;p&gt;An alternative that I've always liked is to use inner-classes to test your code, like this:&lt;/p&gt;&lt;p&gt;public class Foo &lt;br&gt;{&lt;br&gt;   private void Bar()&lt;br&gt;   {&lt;br&gt;     // Do so work here in a private method&lt;br&gt;   }&lt;/p&gt;&lt;p&gt;#region Unit Tests&lt;br&gt;#if UNIT_TESTS&lt;br&gt;    [TestFixture] public class TestFoo&lt;br&gt;    {&lt;br&gt;        [Test] public void TestBar()&lt;br&gt;        {&lt;br&gt;            Foo foo = new Foo()&lt;br&gt;            foo.Bar();   // inner class can call this method&lt;br&gt;        }&lt;br&gt;    }  &lt;br&gt;#endif&lt;br&gt;#end region&lt;br&gt;}&lt;/p&gt;&lt;p&gt;You simply define UNIT_TESTS in Debug/Release builds if you want test code enabled, and leave it out from your Ship builds.&lt;/p&gt;&lt;p&gt;Also, you'll probably have a using statement wrapper,&lt;/p&gt;&lt;p&gt;#if UNIT_TESTS&lt;br&gt;using MbUnit.Framework;&lt;br&gt;#endif&lt;/p&gt;&lt;p&gt;As an added check, you can write a simple app that does reflection on all the types in the DLL to verify your ship build doesn't have any classes with test attributes.  If no code references the test framework, your ship builds will automatically not load the referenced test framework DLLs, thus allowing you to ship your product like usual without pulling in test DLL dependencies (and associated bloat and licensing issues).&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Doug de la Torre</dc:creator><pubDate>Sat, 31 Oct 2009 03:23:43 -0000</pubDate></item><item><title>Re: Unit Test Private Methods in Visual Studio</title><link>http://www.emadibrahim.com/2008/07/09/unit-test-private-methods-in-visual-studio/#comment-10146841</link><description>&lt;p&gt;Sorry, but the last time I used c++ was in college :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emad</dc:creator><pubDate>Thu, 28 May 2009 07:47:32 -0000</pubDate></item><item><title>Re: Unit Test Private Methods in Visual Studio</title><link>http://www.emadibrahim.com/2008/07/09/unit-test-private-methods-in-visual-studio/#comment-10088194</link><description>&lt;p&gt;Do you know of a way that you can do this with managed C++ that references unmanaged C++ types? Please see this question: &lt;a href="http://stackoverflow.com/questions/916507/how-to-convert-a-user-defined-unmanaged-type-to-a-managed-type" rel="nofollow noopener" target="_blank" title="http://stackoverflow.com/questions/916507/how-to-convert-a-user-defined-unmanaged-type-to-a-managed-type"&gt;http://stackoverflow.com/qu...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jared</dc:creator><pubDate>Wed, 27 May 2009 12:32:05 -0000</pubDate></item><item><title>Re: Unit Test Private Methods in Visual Studio</title><link>http://www.emadibrahim.com/2008/07/09/unit-test-private-methods-in-visual-studio/#comment-7337975</link><description>&lt;p&gt;Brilliant Idea, been looking for a straight forward solution to this scenerio that did not invlove using heavyweight reflection. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">stephen</dc:creator><pubDate>Thu, 19 Mar 2009 05:34:51 -0000</pubDate></item></channel></rss>