Unit testing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Unit testing

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    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

  2. #2
    Join Date
    Dec 2008
    Posts
    3

    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.

  3. #3
    Join Date
    Dec 2008
    Posts
    3

    Talking Re: Unit testing

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

  4. #4
    Join Date
    Dec 2008
    Posts
    4

    Re: Unit testing

    Quote Originally Posted by linxu View Post
    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.

  5. #5
    Join Date
    Dec 2008
    Posts
    4

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,000

    Re: Unit testing

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Dec 2008
    Posts
    3

    Re: Unit testing

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

  8. #8
    Join Date
    Jul 2008
    Posts
    3

    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

  9. #9
    Join Date
    Dec 2008
    Posts
    2

    Re: Unit testing

    Quote Originally Posted by wlater View Post
    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

  10. #10
    Join Date
    Dec 2008
    Posts
    2

    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

  11. #11
    Join Date
    Dec 2008
    Posts
    4

    Re: Unit testing

    Quote Originally Posted by oliver_mk View Post
    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.

  12. #12
    Join Date
    Dec 2008
    Posts
    4

    Re: Unit testing

    Quote Originally Posted by linxu View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center