none
How to add C++ unit tests to an existing project? RRS feed

  • Question

  • Hello all,

    I have Visual Studio 2015 Community. I have a C++ project that I created by selecting Visual C++ > General > Empty Project in the New Project window.

    I am reading "Unit testing existing C++ applications with Test Explorer".

    This page explains how to add unit tests to an existing Visual Studio 2015 C++ project. My project is compiled as an .exe file, so I am referring to "To link the tests to the object or library files" heading in the page.

    It says: "On the File menu, choose New, Project, Visual C++,Test, C++ Unit Test Project.", but I do not have such a choice (I only have "Managed Test Project" and "Native Unit Test Project").

    Also, when the page reads "add the names of the .obj or .lib files.", am I supposed to enter the names of every .obj file of the project I want to test in "ProjectToTest/Debug"? What is the syntax?

    Lastly, it also tells me to "add the header directory of the project under test.", what is the header directory? The directory containing all the .h files? What if the project is using the same directory for header and code files?


    Thanks

    Friday, May 5, 2017 4:19 PM

All replies

  • Hi Louis,

    Here is page you are reading right?

    https://msdn.microsoft.com/en-us/library/hh419385.aspx

     

    >> It says: "On the File menu, choose New, Project, Visual C++,Test, C++ Unit Test Project.", but I do not have such a choice (I only have "Managed Test Project" and "Native Unit Test Project").

    It should be like this. You will choose the unit test project according to your project if it’s written by Native C++.

     

    >> Also, when the page reads "add the names of the .obj or  .lib files.", am I supposed to enter the names of every .obj file of the project I want to test in "ProjectToTest/Debug"? What is the syntax?

     

    You only do this “if the code under test does not export the functions that you want to test”, then yes, you need add every name of .obj or .lib you want to test.

     

    >>Lastly, it also tells me to "add the header directory of the project under test.", what is the header directory? The directory containing all the .h files? What if the project is using the same directory for header and code files?

    This happens only you add unit test in the same project, so it just answers it your question.

     

     

    Please feel free to let me know if misunderstood.

     

     

    Hope it helps.

     

    Best regards,

    Fletch


    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.


    • Edited by Fletch Zhou Monday, May 8, 2017 8:15 AM
    • Proposed as answer by Fletch Zhou Tuesday, May 9, 2017 2:32 AM
    Monday, May 8, 2017 8:15 AM