I get this error, but I donโt know how to fix it.
I am using Visual Studio 2013. I made the solution name MyProjectTest. This is the structure of my test solution:

-function.h
#ifndef MY_FUNCTION_H #define MY_FUNCTION_H int multiple(int x, int y); #endif
-function.cpp
#include "function.h" int multiple(int x, int y){ return x*y; }
-main.cpp
#include <iostream>
I'm new at this; it is a simple program and it works without errors. I read on the Internet and was interested in unit test, so I created a test project:
File> Create> Project ...> Installed> Templates> Visual C ++> Test> Native Unit Test Project>
Name: UnitTest1 Solution: Add to solution Then the location automatically switches to the path of the current open solution This is the folder structure of the solution:

I just edited the unittest1.cpp file:
#include "stdafx.h" #include "CppUnitTest.h" #include "../MyProjectTest/function.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; namespace UnitTest1 { TEST_CLASS(UnitTest1) { public: TEST_METHOD(TestEqual) { Assert::AreEqual(multiple(2, 3), 6);
But I get error LNK2019: unresolved external character. I know that the implementation of the multiple function is missing. I tried to delete the function.cpp file, and I replaced the declaration with a definition, and it started. But writing a declaration and definition in the same file is not recommended. How can I fix this error without doing this? Should I replace #include "../MyProjectTest/function.cpp" with unittest.cpp? (I am not very good at English.)
c ++ testing error-handling lnk2019
phibao37 Nov 10 '13 at 4:47
source share