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);
}
};
}
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.