I am starting to work on a project and want to have unit-testing. So, i initially laid out my directory structure like this:
project/src/
project/doc/
project/tools/
project/tests/
However, I bumped into a problem which I didn't consider before. When I include some class in my tests i am getting "unresolved external symbol". Most likely because the h/cpp files are outside of the tests/ directory.
For example, if i have:
project/src/MyClass.h
project/src/MyClass.cpp
project/tests/TestMyClass.cpp
and in TestMyClass.cpp i do:
#include "../src/MyClass.h"
I get linker errors when i try to instantiate a MyClass object (unresolved external symbol). So, I can do:
#include "../src/MyClass.h"
#include "../src/MyClass.cpp"
in TestMyClass.cpp , and everything is fine. I could just include the .cpp for that matter since it will pull the header with itself, but it looks very wrong. After all, the .cpp is not a header and hence not even supposed to be included.. ever.
I would appreciate very much if someone can give me some correct solution to this. I could copy the h/cpp in the tests directory, but that also seems wrong because every time i change something I'll need to update the tests/ copy.
I could also create links instead of copies... but it still doesn't sound like a good solution :-/
Thanks in advance
project/src/
project/doc/
project/tools/
project/tests/
However, I bumped into a problem which I didn't consider before. When I include some class in my tests i am getting "unresolved external symbol". Most likely because the h/cpp files are outside of the tests/ directory.
For example, if i have:
project/src/MyClass.h
project/src/MyClass.cpp
project/tests/TestMyClass.cpp
and in TestMyClass.cpp i do:
#include "../src/MyClass.h"
I get linker errors when i try to instantiate a MyClass object (unresolved external symbol). So, I can do:
#include "../src/MyClass.h"
#include "../src/MyClass.cpp"
in TestMyClass.cpp , and everything is fine. I could just include the .cpp for that matter since it will pull the header with itself, but it looks very wrong. After all, the .cpp is not a header and hence not even supposed to be included.. ever.
I would appreciate very much if someone can give me some correct solution to this. I could copy the h/cpp in the tests directory, but that also seems wrong because every time i change something I'll need to update the tests/ copy.
I could also create links instead of copies... but it still doesn't sound like a good solution :-/
Thanks in advance
Comment