user57034: I have an Arduino project where the file structure looks like this
myProject/
    myProject.ino
    ImportantClass1.hpp 
    ImportantClass1.cpp
    ImportantClass2.hpp 
    ImportantClass2.cpp
    Etc….


It compiles and runs fine. No problem pulling the cpp and hpp files into the ino program. However to really make sure of reliability I want to make additional ino files for unit testing of importantClass1 & etc. I have made files importantClass1UnitTest.ino & importantClass2UnitTest.ino however these can’t be in the same dir as the respective source files as the arduino compiler requires the ino file and the dir to have the same name.
The tests run when I move the files around. But I am not happy with that, I want to be able to run the tests at any time with the standard arduino compiler without having to script filecopy commands.
If I put the unit test in its own dir separate to the class source and #include using the full path it also works. However this solutions is not portable, when I (or any collaborator) pull the project from git hub on any other computer the paths are wrong and it doesn’t work.
Where am I going wrong? How can I do this so as to avoid moving/copying files and also avoid using full paths?

user313: One way to do it is to use preprocessor conditionals. Name your project file and unit-test files with .cpp extensions and put them in a subfolder (called "sources" in my example). Then your .ino file would only be used to instruct the preprocessor which of the several "main" file to start compiling with:
myProject.ino:
/*
 * myProject.ino
 * define which "main" CPP file to compile:
 */

#define PRODUCTION
// #define UNITTEST1
// #define UNITTEST2
// #define UNITTEST3

// The compilation starts here with the requested "main" file:
#if defined PRODUCTION
#include "sources/myProject.cpp"

#elif defined UNITTEST1
#include "sources/unitTest1.cpp"

#elif defined UNITTEST2
#include "sources/unitTest2.cpp"

#elif defined UNITTEST3
#include "sources/unitTest3.cpp"

#else
// If nothing defined, compile for production
#include "sources/myProject.cpp"
#endif

/* END */

Only the .ino file would need to be edited to compile one of the unit tests, and only one project file would be needed.
Update:
"did you try it? "
Yes, and it does work. The only caveat I'd add is: don't name your subfolder "src" - that seems to be a magic-name to the IDE, and you'll get complaints of compilation errors (multiple definitions) if you use it. And further, if you try it, you can't get back simply by changing the folder's name (on disk and in the code); you'll have to restart the IDE as well.
I tested it with v1.8.19 of the IDE.

57034: <p>I have an Arduino project where the file structure looks like this</p>
<pre><code>myProject/
    myProject.ino
    ImportantClass1.hpp 
    ImportantClass1.cpp
    ImportantClass2.hpp 
    ImportantClass2.cpp
    Etc….

</code></pre>
<p>It compiles and runs fine. No problem pulling the cpp and hpp files into the ino program. However to really make sure of reliability I want to make additional ino files for unit testing of importantClass1 &amp; etc. I have made files <code>importantClass1UnitTest.ino</code> &amp; <code>importantClass2UnitTest.ino</code> however these can’t be in the same dir as the respective source files as the arduino compiler requires the ino file and the dir to have the same name.</p>
<p>The tests run when I move the files around. But I am not happy with that, I want to be able to run the tests at any time with the standard arduino compiler without having to script filecopy commands.</p>
<p>If I put the unit test in its own dir separate to the class source and <code>#include</code> using the full path it also works. However this solutions is not portable, when I (or any collaborator) pull the project from git hub on any other computer the paths are wrong and it doesn’t work.</p>
<p>Where am I going wrong? How can I do this so as to avoid moving/copying files and also avoid using full paths?</p>
 313: <p>One way to do it is to use preprocessor conditionals. Name your project file and unit-test files with <code>.cpp</code> extensions and put them in a subfolder (called &quot;sources&quot; in my example). Then your <code>.ino</code> file would only be used to instruct the preprocessor which of the several &quot;main&quot; file to start compiling with:</p>
<p>myProject.ino:</p>
<pre><code>/*
 * myProject.ino
 * define which &quot;main&quot; CPP file to compile:
 */

#define PRODUCTION
// #define UNITTEST1
// #define UNITTEST2
// #define UNITTEST3

// The compilation starts here with the requested &quot;main&quot; file:
#if defined PRODUCTION
#include &quot;sources/myProject.cpp&quot;

#elif defined UNITTEST1
#include &quot;sources/unitTest1.cpp&quot;

#elif defined UNITTEST2
#include &quot;sources/unitTest2.cpp&quot;

#elif defined UNITTEST3
#include &quot;sources/unitTest3.cpp&quot;

#else
// If nothing defined, compile for production
#include &quot;sources/myProject.cpp&quot;
#endif

/* END */
</code></pre>
<p>Only the .ino file would need to be edited to compile one of the unit tests, and only one project file would be needed.</p>
<p>Update:
&quot;did you try it? &quot;</p>
<p>Yes, and it does work. The only caveat I'd add is: don't name your subfolder &quot;src&quot; - that seems to be a magic-name to the IDE, and you'll get complaints of compilation errors (multiple definitions) if you use it. And further, if you try it, you can't get back simply by changing the folder's name (on disk and in the code); you'll have to restart the IDE as well.
<br>I tested it with v1.8.19 of the IDE.</p>
