What is the recommended directory structure for tests?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emibt08
    New Member
    • Oct 2008
    • 25

    What is the recommended directory structure for tests?

    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
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Unresolved externals are a linker error and nothing to do with directory structure. The linker is complaining because you have declared functions (class methods) that are not defined anywhere because the please they have been defined, MyClass.cpp has not been compiled to an object and the object has not been included in the link.

    I Use a very similar structure to yours. When you compile the test directory you have to compile the src directory too and link all those objects together.

    Comment

    • emibt08
      New Member
      • Oct 2008
      • 25

      #3
      Thank you for your response Banfa. It seems that I forgot to link the object files at the end :-|
      It's all good now. Thank you

      Comment

      Working...