locked
Write Unit Testing project for Release Build RRS feed

  • Question

  • Hi All,

    I am working in a project where we don't have Debug binaries. We have only release binaries.

    My intention to write unit test for VC++ binaries which are exe and dlls.

    While search on web, i found there is direct support in VS2017 to create Test project and can write unit test for my code base.

    I created a sample project in release mode But while executing code coverage i am getting 0% coverage.

    I read this article and here the author mentioned something related to my problem.

    NOTE: There is a known issue where Code Coverage will not work in C++ unless /DEBUG:FULL is selected as the debugging configuration. By default, the configuration is set to /DEBUG:FASTLINK instead. You can switch to /DEBUG:FULL by doing the following:

    So is there anyway to mitigate this issue or is any other tools available to fulfill my need. Waiting for your response.

    Regards

    g_shanmuga


    Wednesday, March 18, 2020 6:45 AM

All replies

  • Hi g_shanmuga,

    Welcome to MSDN forum.

    Not sure if there is something wrong with settings or configuration, I just test on my side by creating a new simple C++ application and a Native Unit Test Project(VC++) and build it under “Release” configuration. Then run “Analyze Code coverage for Selected Tests”, the “Code Coverage Results” window displayed that covered 100% Blocks.

    If possible, could you share us with a reproduced simple sample, and upload it to OneDrive then post link here, I will go to download and test on my side.

    In addition, you could refer to following documents: Use code coverage to determine how much code is being tested and Write unit tests for C/C++ in Visual Studio.

    Feel free to let me know, if I misunderstand you.

    Kind Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 18, 2020 9:23 AM
  • Hi Tianyu,

    Thanks for the response, mistake has been found out and rectified from my side.

    Now i have added a class inside my unit test project and testing both of its methods to check code coverage.

    File : MyMathCls.cpp

    int MyMathCls::Add(int a, int b)
    {
    if (a != 0 && b != 0)
    return a + b;
    else
    return a + b;
    }
    int MyMathCls::subract(int a, int b)
    {
    if (a != 0 && b != 0)
    return a - b;
    else
    return a - b;
    }

    After executing "Analyse code coverage" and "show code coverage coloring".

    Covered and uncovered codes are marked with different color in my unittest1.cpp but not in MyMathCls.cpp which is the one need code coverage data.

    Sorry i am not able to upload pic, because msdn wont allow me and getting popup"until they verify my account"

    Am i done anything wrong in terms of getting code coverage coloring.

    Regards

    g_shanmuga


    Wednesday, March 18, 2020 1:17 PM
  • Hi g_shanmuga,

    Thank you for your feedback.

    I’m afraid, this is by designed, perhaps, Unit Test for C++ framework needs something from debug builds to analyze the code coverage for your C++ file.

    I also tested with other kinds of projects(C++) and they all fail to display the code coverage for C++ file, except changing “Release” to “Debug” and “Generate Debug Info” from “Generate Debug Information optimized for fast links(/DEBUG:FASTLINK)” to “Generate Debug Information optimized for sharing and publishing (DEBUG:FULL)”.

    Sorry for this inconvenience and any feedback will be expected.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 19, 2020 3:27 AM
  • Hi Tianyu,


    As like you suggested am able to see the code coverage coloring information only in Debug builds with (DEBUG:FULL) option enabled.

    But the challenge which is in-front of me is, we have only release build for our product, no debug build as of now. The reason which i got from my technical specialist was ,it has multiple exes with multi threading are running at the same time so debugging is not possible, hence we are only using Trace to analysis any failure.

    Now i am trying to write unit test for our all VC++ dlls as well as exes, so i have two choice

    1. Find out any available tool which supports unit test on release binaries to get code coverage report( With license cost ) . Do know any good licensed tool ? Otherwise

    2. I have to work on creating release build for all of my binaries ( One of the tedious job ) and start using Native Unit Test Project or Google test.

    What would be the best, easy and feasible way to achieve this.

    Regards

    g_shanmuga

    

    Thursday, March 19, 2020 4:57 AM
  • Hi g_shanmuga,

    Sorry for delay in reply.

    Another way to use unit test in Visual Studio is to use Managed Test project(C++) instead of Native Unit Test(C++). I consider this could work.

    Below are the steps to use Managed Test project:

    #1. Create a C++ project for testing and add a Unit Test project into the solution(choose Managed Test Project instead of Native Unit Test Project).

    #2. Add a reference to the C++ project into the Unit Test project.

    #3. Right-click “Source Files” in Unit Test Project => Add => Unit Test…

    #4. Include the header file, and write the unit test codes to the added project(Unit Test) mentioned above.

    #5. Run test and “Analyze Code Coverage” => “Show Code Coverage Coloring” then check if it works this time.


    Hope this could help you and any feedback will be expected.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, March 19, 2020 7:14 AM
  • Hi Tianyu,

    Thanks for the response.

    I hope the solution which you mentioned should work and i would like to try that by myself  but unfortunately i am not able to find out such "Managed Test Project " in any of the test category project listed out by VS 2017.  

    I am using VS 2017 Enterprise edition and set C++ and VC++ as my default environment.

    Regards

    g_shanmuga 

    Thursday, March 19, 2020 11:51 AM
  • Hi g_shanmuga,

    Thanks for your feedback.

    Yes, I also tested with VS 2017 Enterprise edition.

    Please make sure that you have installed “Desktop development with C++” workload and “C++/CLI support” component in VS Installer.

    Hope it works and any feedback will be expected.

    Sincerely,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 20, 2020 1:01 AM
  • Hi Tianyu,

    I have installed “Desktop development with C++” workload and “C++/CLI support” component in VS Installer.

    While adding new project in VisualC++ Test i have 

    1. Native Unit Test Project

    2. Google Test

    It is not listing "Managed Test Project".

    Regards

    g_shanmuga


    Friday, March 20, 2020 5:50 AM
  • Hi g_shanmuga,

    Thanks for your feedback.

    I checked again by reinstalling a new VS 2017 Enterprise on a new computer, just selected and installed “Desktop development with C++” workload. After that I could find this project template, even from File => New => Project…

    Do you use latest version of VS 2017 Enterprise? If not, you could try to update it to the latest version from Help => Check for Updates. Also, you could try to repair it from VS Installer => VS 2017 => More => Repair.

    Feel free to contact me.

    Best Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 20, 2020 7:28 AM
  • Hi g_shanmuga,

    Sorry to bother you.

    Is your issue solved? Please feel free to let me know, if you have any update.

    Any feedback will be expected.

    Sincerely,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 31, 2020 8:17 AM