I've got a (qt) program in visual studio that I would like to create (qt) unit tests for. I thought the best way to do this would be to have the unit tests in a separate project in the same Visual Studio solution and then include the classes I want to test from the other project.
However, I created a second project for the unit tests, and when I include a class from the first project and initialize it, I get a linker error such as the following:
SimpleTest.obj : error LNK2019: unresolved external symbol "public:
__cdecl SimpleClass::SimpleClass(void)" (??0SimpleClass@@QEAA@XZ) referenced in function "private: void __cdecl SimpleTest::testSimpleClass(void)" (?testSimpleClass@SimpleTest@@AEAAXXZ)
I've added the directory of .h and .cpp files to the additional includes directory in properties of the test project, and I've added the .lib file output with the exe from the first project in the additional library directories of the second projects properties, but none of this seems to have fixed this linker error and allowed the tests to run. What am I missing to get my project to successfully compile?
For reference, the files I have are:
SimpleClass.h (In project 1):
#pragma once
class SimpleClass
{
public:
SimpleClass();
};
SimpleClass.cpp (In project 1):
#include "SimpleClass.h"
SimpleClass::SimpleClass()
{
}
SimpleTest.h (In project 2):
#pragma once
#include <QTest>
class SimpleTest : public QObject
{
Q_OBJECT
private slots:
void testSimpleClass();
};
SimpleTest.cpp (In project 2):
#include "SimpleTest.h"
#include "SimpleClass.h"
void SimpleTest::testSimpleClass()
{
SimpleClass *splClass = new SimpleClass();
}
main.cpp (In project 2):
#include <QtTest>
#include "testqstring.h"
#include "SimpleTest.h"
int main(int argc, char** argv) {
QApplication app(argc, argv);
TestQString testSuite1;
SimpleTest testSuite2;
return QTest::qExec(&testSuite1, argc, argv) | QTest::qExec(&testSuite2, argc, argv);
}