locked
Can we use Visual Studio 2010 unit test framework for unit testing of C++(unmanged code) RRS feed

  • Question

  • Hi

    Is it feasible to use VS 2010 unit test framework for unit testing of C++ ( unmanged code)?

    If not possible ,is there any way to integrate GoogleTest & GoogleMock  or Visual Assert  or CppUnit

    with VS 2010?

    Thanks

    Vijay

     

     

     

    Wednesday, March 9, 2011 5:18 AM

All replies

  • Hi Vijay,

    There is no unit test support for unamanged C++ code. However, you can refer this article for various testing methods of C++ code http://msdn.microsoft.com/en-us/library/ms243171.aspx

    Thanks,

    Anuj

    Wednesday, March 9, 2011 6:18 AM
  • There is this tool - WinUNit from Microsoft to unit test native C/C++ applications and seems to have nice integration with Visual Studio. Check this article "WinUnit simplifies Unit Testing for Native C++ Applications".
    Anand K Reddy
    akx++ Solutions

    • Proposed as answer by Anand K Reddy Friday, January 2, 2015 9:11 PM
    • Edited by Anand K Reddy Tuesday, August 4, 2015 4:38 PM hyperlink pointed right
    Tuesday, May 17, 2011 5:40 PM
  • Hi

    Is it feasible to use VS 2010 unit test framework for unit testing of C++ ( unmanged code)?

    If not possible ,is there any way to integrate GoogleTest & GoogleMock  or Visual Assert  or CppUnit

    with VS 2010?

    Thanks

    Vijay

     

     

     

     

    The good news (well it means you have to wait a while and spend more money :)) is that it was recently mentioned that the next Visual Studio will have support for C++ unit testing.


    Kevin
    Friday, May 27, 2011 9:26 AM
  • To answer your question specifically - It is not feasible to use VS 2010 for unit testing native applications written in C++ as per me, unless otherwise written in C++/CLI but again, I never unit tested them too.

    I guess - not 100% sure - CppUnit can be integrated with VS2010 but I'm not sure about the feasiability. But, I would recommend WinUnit (a framework for unit testing native code by Maria Blees from Microsoft) to test native code over others, which is very simple and can be integrated nicely into VS 2009 & 2010 that I know with hands on. Also, have come to know that VS 2011 is having a nice native code unit testing support in built.


    Anand K Reddy
    akx++ Solutions


    Tuesday, June 12, 2012 9:31 PM
  • It seems to me that in some sense the answer depends on what the C++ (unmanaged code) does and how much of it you want to unit test.

    For example, if the C++ code implements a COM object then C# code can invoke that COM object using an Interop class generated by tlbimp.exe - either by manually running the tool or by using Visual Studio Add Reference | COM Reference to get Visual Studio to run tlbimp.exe for you.

    Similarly, if the C++ code implements a DLL that exports a number of entry points then you can call those entry points using DllImport.  Admittedly you have to write more C# code yourself to describe the DllImport entry points but the PINVOKE.NET web site and Adam Nathan's book along with various tools and other reading material can help.

    Even if COM Interop and DllImport are not possible, you could perhaps create a managed C++ test harness to expose your unmanaged C++ code to C# and so build unit tests that way.

    Of course in all cases you are limited to testing what the managed code can 'see' and you run the risk of introducing false positives due to bugs in the testing harness rather than bugs in your code under test.

    Alternatively, as Anand suggested above, you might consider moving up to Visual Studio 2012 which supports Native C++ unit tests.

    • Edited by Frank Boyne Sunday, October 7, 2012 7:12 AM Add link to Visual Studio 2012 native tests
    Sunday, October 7, 2012 6:01 AM