<?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>Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx</link><description>Hi there! I&amp;rsquo;m John Socha-Leialoha and I&amp;rsquo;m a big fan of TDD. When I asked around about writing C++ tests, I was told there isn&amp;rsquo;t any support for C++ unit tests in Visual C++. Not true. Check this blog post where I tell you what&amp;rsquo;s</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10111540</link><pubDate>Tue, 04 Jan 2011 17:28:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10111540</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><description>&lt;p&gt;@Joe. I don&amp;#39;t agree. I was introduced to TDD about 5 years ago when I was writing Windows Mobile code. In that case, I would run the unit tests all the time on the desktop, and every now and then on the mobile device. Since Windows Mobile is a subset of Windows, there was no gaurantee that the behavior would be the same between the desktop and the device. However, even though there wasn&amp;#39;t complete fidelity, our productivity gain was huge.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m doing now, and what resulted in my article, is testing desktop software on the desktop. Because my tests are true unit tests, not component or integration tests, they 100% valid. I have yet to run into a case where the behavior was any different between the testing environment and the production code. The actual code that I&amp;#39;m testing is always running as native code. At this point I have almost 400 unit tests, and they&amp;#39;ve saved us a number of times from making breaking changes.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10111540" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10110090</link><pubDate>Thu, 30 Dec 2010 02:31:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10110090</guid><dc:creator>H Malthouse</dc:creator><description>&lt;p&gt;Thanks for linking this Diego. (I&amp;#39;m assuming it was you as you&amp;#39;re answering all the Qs)&lt;/p&gt;
&lt;p&gt;When I first looked at using VS Test I recoiled at the unfamiliar C++/CLI code, but John&amp;#39;s post is a great getting started guide. Very clear and to the point. I think I&amp;#39;ll give it a go with my next project.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10110090" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10109998</link><pubDate>Wed, 29 Dec 2010 20:52:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10109998</guid><dc:creator>Diego Dagum</dc:creator><description>&lt;p&gt;@Michael Hamilton, your point is certainly valid. In the cross-platform scenario you mentioned this out-of-box approach is not adequate and probably one of those frameworks some other readers said above we&amp;#39;ll be better suited. The good news about those alternative testing frameworks is that many are enabled to be hooked into VS as extensions.&lt;/p&gt;
&lt;p&gt;@Joe, I wish that were the reason of our buggy code: it&amp;#39;s just a matter of swtching to CppUnit and we are leading the race again! ;-D&lt;/p&gt;
&lt;p&gt;Seriously, if you found a definition that specifies that the validity of a unit test depends on the fact that the tester portion is built in the same environment than the tested part, I&amp;#39;ll conceal you&amp;#39;re right. Otherwise, as long as it fails when it&amp;#39;s expected to fail, works fine when it&amp;#39;s expected so, sorry for disagreeing here, friend. Related question: if you had to unit test for correctness a stored procedure, should the test itself be another stored procedure?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10109998" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10109466</link><pubDate>Tue, 28 Dec 2010 07:29:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10109466</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;Sorry, Diego, but your wrong. You test native code with native code, anything else is NOT testing, but self-indulgent crap. Perhaps this explains so much buggy Microsoft code.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10109466" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10109457</link><pubDate>Tue, 28 Dec 2010 06:49:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10109457</guid><dc:creator>Michael Hamilton</dc:creator><description>&lt;p&gt;&amp;quot;Being VS an already OS-dependent tool, getting its out-of-box testing mechanism based in an OS-dependent technology like C++/CLI doesn’t add/subtract anything, does it? ;-)&amp;quot;&lt;/p&gt;
&lt;p&gt;It is fairly common to want to port a project to other platforms which may require other compilers, tools, and environments with the same code base. &amp;nbsp;If you want to open source anything you cannot control what people are going to be running things on. &amp;nbsp;If you&amp;#39;re building libraries for commercial release it&amp;#39;s a bit clunky to have a unit test so environment specific.&lt;/p&gt;
&lt;p&gt;Not being able to bring unit tests across easily, let&amp;#39;s say to a unix based system, seems like a fairly major stopping point. &amp;nbsp;Even if you are certain you don&amp;#39;t need to port your project today it&amp;#39;s a little harder to say you&amp;#39;ll never need to. &amp;nbsp;If you can&amp;#39;t easily bring your unit tests across that&amp;#39;s a personal deal breaker. &amp;nbsp;This is beyond the method itself feeling kind of clunky and contrived and setup heavy.&lt;/p&gt;
&lt;p&gt;While this method may be &amp;quot;interesting&amp;quot; I think I&amp;#39;ll be sticking with one of several in-language implementations. &amp;nbsp;Recently been using boost&amp;#39;s testing framework with some success, still playing with others though.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10109457" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10109443</link><pubDate>Tue, 28 Dec 2010 05:57:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10109443</guid><dc:creator>Diego Dagum</dc:creator><description>&lt;p&gt;@Joe While desirable to keep the testing context as much production-like as possible, “unit testing” per-se is all about correctness proving for a single, isolated functionality (like a function or method) without much said about the environment (not at least in its formal definition). To put a couple of examples, unit testing for mobile application components aren’t usually being tested in the mobile device itself –not event in a device-emulated environment-. Likewise, we typically use XML files to mimic databases or web services responses, thus avoiding dealing with connectivity issues, etc, and that mocking technique doesn’t invalidate unit tests either.&lt;/p&gt;
&lt;p&gt;Yet, your point about potential failures in the interop mechanism are valid although, do we really know about those interop inconsistencies today? My point here is about giving some likelihood to the current status of this IJW interop technique instead of discarding it right away: it has been out there for years, having matured with every new version of VS, being today the preferred approach for managed / unmanaged interoperability.&lt;/p&gt;
&lt;p&gt;@kdprw: Being VS an already OS-dependent tool, getting its out-of-box testing mechanism based in an OS-dependent technology like C++/CLI doesn’t add/subtract anything, does it? ;-)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10109443" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10109039</link><pubDate>Sat, 25 Dec 2010 20:47:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10109039</guid><dc:creator>kdprw</dc:creator><description>&lt;p&gt;What a great news: in order to write unit tests for your C++ code in VS, all you need is to use some non C++ (and effectively OS-dependent?) framework which, based on the comments here and the actual blog post, doesn&amp;#39;t even seem to be suitable for testing C++ code.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10109039" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10109032</link><pubDate>Sat, 25 Dec 2010 18:31:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10109032</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;This is still mostly bogus unless your DLL is intended to be used from .NET. Unit testing does not mean you more or less test the code as intended, but test it actually as intended. There is a big difference. So, for example, how do you know whether an error was caused by your code or by .NET interop? (I use a .NET interface to my native DLLs to do system tests, but not unit tests else the testing would be hopelessly incomplete.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10109032" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10108673</link><pubDate>Thu, 23 Dec 2010 19:10:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10108673</guid><dc:creator>Diego Dagum</dc:creator><description>&lt;p&gt;You&amp;#39;re right, Ricardo. In fact, that consideration is common in C++/CLI - native interoperability. If you take a look to the official documentation about nullptr in C++/CLI (available at &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/4ex65770(v=VS.100).aspx"&gt;msdn.microsoft.com/.../4ex65770(v=VS.100).aspx&lt;/a&gt; ) you&amp;#39;ll find&lt;/p&gt;
&lt;p&gt;&amp;quot;The __nullptr keyword is a Microsoft-specific keyword that has the same meaning as nullptr, but applies to only native code. If you use nullptr with native C/C++ code and then compile with the /clr compiler option, the compiler cannot determine whether nullptr indicates a native or managed null pointer value. To make your intention clear to the compiler, use nullptr to specify a managed value or __nullptr to specify a native value.&amp;quot;&lt;/p&gt;
&lt;p&gt;I want to remind that the native tested functionality, not its managed testing counterpart, is not to be compiled as /clr and therefore any reference to native nullptr (the traditional NULL or (void*)0 before C++0x) is to remain as nullptr. In other words, despite the consideration, you don&amp;#39;t need to touch your logic being tested to make it suitable for this testing framework.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10108673" width="1" height="1"&gt;</description></item><item><title>re: Unit-Testing Native C++ with Visual Studio</title><link>http://blogs.msdn.com/b/vcblog/archive/2010/12/21/unit-testing-native-c-with-visual-studio.aspx#10108489</link><pubDate>Thu, 23 Dec 2010 07:45:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10108489</guid><dc:creator>Ricardo Costa</dc:creator><description>&lt;p&gt;I&amp;#39;ve been using this technique for about a year now and it seems to be working good so far. The only recent downside I&amp;#39;ve met was the introduction of the C++0x nullptr keyword, which we cannot use because the unit tests compiled with /clr interpret nullptr as a managed keyword. We would have to use __nullptr instead on our code to avoid breaking the unit tests.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10108489" width="1" height="1"&gt;</description></item></channel></rss>