# Slow Chat Archives > Slow Chat: C++0x >  Unit testing

## oliver_mk

Hi Microsoft,

I was interested when will be Unit testing integrated for Native applications, like it is in the managed code?

Regards,
Oliver

----------


## linxu

Today you can test native applications using the unit testing framework in VSTS, so long you write your tests as managed code. You'll get the full experience with that including the colorization in the editor. (The colorization tells you what code you are covering with your unit tests and what you are not.)

Of course, the giant caveat here is that you have to write your tests in some kind of managed code. This is only a viable approach if your project is componentized in some way. For example if you are using COM I suggest writing your unit tests in managed code and using COM interop which is quite nice. If you have dlls I suggest C++/CIL. It's also a pretty good experience. Unforunately if you have static .libs or components that are part of an executable it's much harder to test those today. You can make your test project C++/CIL and actually include the source files in there but I will admit it's not a good experience. 

This ties into your deeper question which is, "when will there be first class native unit testing?" We're very aware that the unit testing experience for native code isn't the best and we want to improve it. For Dev10, unforunately, we won't be improving this situation any. We're definitely taking a look at this for the next release, though. We know it's a frustrating situation.

If you want to know more about how to use the unit testing framework today to test your native code I'll be happy to give you pointers.

----------


## linxu

Hm, I should also state that I work in the Visual C++ team here at Microsoft  :Big Grin:

----------


## wlater

> Today you can test native applications using the unit testing framework in VSTS, so long you write your tests as managed code. You'll get the full experience with that including the colorization in the editor. (The colorization tells you what code you are covering with your unit tests and what you are not.)


Could you go into a bit more detail (or post a link to same info) on how to get the unit test covered native code to be colorized in the editor? I have done a unit test in C++/CLI to test a C++ native code class in a DLL and have been successful in getting it to execute correctly. (BTW, I also did the same class unit test in CppUnit and Boost::Test for comparison). However, I never did see any code coverage indication for the native code. Did I simply forget an option somewhere or missing something simple? Thanks.

Getting code coverage indication in the native code automatically would be a big plus for the MS Unit Test approach compared to CppUnit or Boost::Test and would compensate for some of the negatives for needing to write the test in managed code to begin with.

----------


## wlater

Re-reviewing Visual Studio help, I'm guessing I need one of the Visual Studio Test editions to get code coverage as I do not have a Code Coverage selection in my test run configuration dialog as per VS Help. I think that was the conclusion I came to the 1st time I looked into this but your post gave me new hope.  :Smilie:  

So is this the case: that I need one of the Test editions to get code coverage? I am only using the Professional edition.

----------


## dglienna

VSTS = http://msdn.microsoft.com/en-us/vsts2008/default.aspx

----------


## linxu

Yes, you need either Test Edition, Developer Edition, or the "full stack " team suite edition, as dglienna pointed out. Sorry  :Frown:

----------


## amohindra

Hi,

Article on MSDN explains the unit test framework for Visual C++ 

http://msdn.microsoft.com/en-us/library/ms243171.aspx.

Thanks,

Amit Mohindra
Visual C++ Team

----------


## oliver_mk

> Could you go into a bit more detail (or post a link to same info) on how to get the unit test covered native code to be colorized in the editor? I have done a unit test in C++/CLI to test a C++ native code class in a DLL and have been successful in getting it to execute correctly. (BTW, I also did the same class unit test in CppUnit and Boost::Test for comparison). However, I never did see any code coverage indication for the native code. Did I simply forget an option somewhere or missing something simple? Thanks.
> 
> Getting code coverage indication in the native code automatically would be a big plus for the MS Unit Test approach compared to CppUnit or Boost::Test and would compensate for some of the negatives for needing to write the test in managed code to begin with.


Hi,

Are you saying that you have unit tests written in C++/CLI for code that is written in Native C++ without CLR support? If yes, can you provide me some points how to do it?

Thanks,
Oliver

----------


## marobert-MS

Hi oliver_mk,

As a first step, you might want to try modifying your C++/CLI unit test project to use /clr as opposed to /clr:safe. The latter is the default, but the former option will allow you to interact with native code.

Mark Roberts
Visual C++ Team

----------


## wlater

> Are you saying that you have unit tests written in C++/CLI for code that is written in Native C++ without CLR support? If yes, can you provide me some points how to do it?


Yes, that's correct. I have a native C++ class compiled within a fully native DLL. I then have unit tests written in C++/CLI with objects of the native class. There's really not much special to tell in terms of how to do it. I simply used the Wizard to create the unit test outlines and then added in my specific tests. Biggest problem was that the particular native class I used made use of CString in its interface and C++/CLI won't work with that directly. So anytime I needed to deal with a CString (such as compare that it matched a known pattern), I had to convert it to a String using a String constructor. Little bit of extra overhead, but not too bad.

----------


## wlater

> Yes, you need either Test Edition, Developer Edition, or the "full stack " team suite edition, as dglienna pointed out. Sorry


At least now you have my request for what to include in VS10 Professional Edition.  :Wink:

----------

