1

I am trying to link my Native Test Project to existing project in the same solution. In #include I am writing path to the header of class I am trying to test.

When I Run Test in Test Explorer I get build error:

Error 1 error LNK2019: unresolved external symbol "public: __thiscall DataManager::DataManager(void)" (??0DataManager@@QAE@XZ) referenced in function "public: void __thiscall MyProject.Tests::UnitTest1::TestMethod1(void)" (?TestMethod1@UnitTest1@MyProjectTests@@QAEXXZ) D:\Documents\VisualStudio2013\Projects\MyProject\MyProject.Tests\DataManagerTests.obj MyProject.Tests

I found different examples of how to link Native test project to .dll project or Static Library, but not to Windows Application.

Will really appreciate your help.

#include "stdafx.h"
#include "CppUnitTest.h"

#include "D:/Documents/VisualStudio2013/Projects/MyProject/DataManager.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace VideoFaceRecognitionIPCATests
{       
    TEST_CLASS(UnitTest1)
    {
    public:

        TEST_METHOD(TestMethod1)
        {
            DataManager dataManager = DataManager();
            Assert::AreEqual(0, 0);
        }

    };
}
code4fun
  • 35
  • 1
  • 8

2 Answers2

0

You should add the DataManager .lib file to the link input file option. Right click the project, go to properties and select the Linker Input entry. Add you .lib to the Additional Dependencies, specify the path if needed (or add the .lib file to your project)

Ton Plooij
  • 2,583
  • 12
  • 15
  • Do you mean lib file of MyProject? DataManager is my class I want to test. Btw I can't find any lib files in my MyProject folder. – code4fun Apr 23 '16 at 13:40
  • I assume that the DataManager project is a static or dynamic library project. That would then generate a .lib file that needs to be referenced in your unit test project. – Ton Plooij Apr 23 '16 at 14:30
0

I know this is 3 years old now, but for future googlers trying to figure out how to unit test their Windows executable app: Don't try to link your unit test project with your executable project. It won't work (without setting up the exe to export it's functions, and even then it's pretty questionable).

You have a couple of other choices. You can either add your source modules (.cpp) to your unit test project directly, or put your source modules into a static or dynamic library project and link both the executable and the unit test projects with the library.

Chris Olsen
  • 3,243
  • 1
  • 27
  • 41