0

I have a project that looks like this:

xdc/
  hubactions/
    hubconnection.cpp
    hubconnection.h
  uiinterface/
    readme
    uiconnection.cpp
    uiconnection.h
    ...
  uiactions/
    readme
    connectaction.cpp
    connectaction.h
    quitaction.cpp
    quitaction.h
    ...
  utils/
    parser.cpp
    parser.h
    ...

Now I want to start testing before the project becomes too big.

So how should I got about organising my tests? I have come up with two options:

Option 1

xdc/
  hubactions/
    hubconnection.cpp
    hubconnection.h
  uiinterface/
    readme
    uiconnection.cpp
    uiconnection.h
    ...
  uiactions/
    readme
    connectaction.cpp
    connectaction.h
    quitaction.cpp
    quitaction.h
    ...
  utils/
    parser.cpp
    parser.h
    ...
  tests/
    utils/
      parsertest.cpp
    uiinterface/
      uiconnectiontest.cpp
    uiactions/
      connectactiontest.cpp
      quitactiontest.cpp
    hubactions/
      fakehubconnection.cpp
      fakehubconnection.h
    ...

Option 2

xdc/
  hubactions/
    tests/
      fakehubconnection.cpp
      fakehubconnection.h
    hubconnection.cpp
    hubconnection.h
  uiinterface/
    tests/
      uiconnectiontest.cpp
    readme
    uiconnection.cpp
    uiconnection.h
    ...
  uiactions/
    tests/
      connectactiontest.cpp
      quitactiontest.cpp
    readme
    connectaction.cpp
    connectaction.h
    quitaction.cpp
    quitaction.h
    ...
  utils/
    tests/
      parsertest.cpp
    parser.cpp
    parser.h
    ...

Which method is better? Can I do it in a different/better way?

Thanks!

3 Answers 3

1

I like the code structure followed by the Apache Software Foundation (ASF) and its primary build tool, Maven. This structure is Java-centric, but can be applied to other languages. The best C++ plug-in for Maven, in my opinion, follows the ASF structure for C++ and looks like this:

project/
  /src
    /main
      /include
      /c++
    /test
      /include
      /c++

I use this structure and it works out well, and is consistent with my projects written in other languages.

1
  • thanks, I chose this method for the project I'm working on right now :)
    – jrharshath
    Sep 20, 2009 at 7:19
1

I don't think there is a 'better' option.

Personally I perfer option 2, as it keeps the tests physically close to the code being tested.

That said, I'm sure someone will come along with a perfectly good reason to use option 1.

A third option (which I really DON'T like) might be to store the tests with the code being tested (see below). However this tends to clutter up your directory structure too much

xdc/
  hubactions/
    fakehubconnection.cpp
    fakehubconnection.h
    hubconnection.cpp
    hubconnection.h
  uiinterface/
    uiconnectiontest.cpp
    readme
    uiconnection.cpp
    uiconnection.h
    ...
  uiactions/
    connectactiontest.cpp
    quitactiontest.cpp
    readme
    connectaction.cpp
    connectaction.h
    quitaction.cpp
    quitaction.h
    ...
  utils/
    parsertest.cpp
    parser.cpp
    parser.h
    ...
1

An argument for option 1 is that this makes a clearer separation between production code and testing code. As a result it is less likely that testing code will become part of the production code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.