-
December 10th, 2008, 03:13 AM
#1
Unit testing
Hi Microsoft,
I was interested when will be Unit testing integrated for Native applications, like it is in the managed code?
Regards,
Oliver
-
December 10th, 2008, 05:10 PM
#2
Re: Unit testing
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.
-
December 10th, 2008, 05:10 PM
#3
Re: Unit testing
Hm, I should also state that I work in the Visual C++ team here at Microsoft
-
December 11th, 2008, 06:26 PM
#4
Re: Unit testing
 Originally Posted by 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.)
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.
-
December 11th, 2008, 06:46 PM
#5
Re: Unit testing
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.
So is this the case: that I need one of the Test editions to get code coverage? I am only using the Professional edition.
Last edited by wlater; December 12th, 2008 at 04:10 PM.
-
December 11th, 2008, 07:31 PM
#6
-
December 11th, 2008, 09:37 PM
#7
Re: Unit testing
Yes, you need either Test Edition, Developer Edition, or the "full stack " team suite edition, as dglienna pointed out. Sorry
-
December 11th, 2008, 10:44 PM
#8
Re: Unit testing
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
-
December 12th, 2008, 10:59 AM
#9
Re: Unit testing
 Originally Posted by wlater
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
-
December 12th, 2008, 03:42 PM
#10
Re: Unit testing
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
-
December 12th, 2008, 04:02 PM
#11
Re: Unit testing
 Originally Posted by oliver_mk
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.
-
December 12th, 2008, 04:10 PM
#12
Re: Unit testing
 Originally Posted by linxu
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|