views:

327

answers:

3

Hi,

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!

A: 

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
    ...
Glen
+1  A: 

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.

Johan
A: 

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.

SingleShot
thanks, I chose this method for the project I'm working on right now :)
Here Be Wolves