1

I found this example on how to create a project with AUnit tests: https://www.thecoderscorner.com/electronics/microcontrollers/embedded-testing/getting-started-unittesting-arduino/

According to it and projects I have found on github my project structure should look like this:

Application
    src
        SomeComponent.cpp
        SomeComponent.h
    tests
        TestSomeComponent
            TestSomeComponent.ino
    Application.ino

But when I try to run TestSomeComponent.ino with Arduino IDE or VSC with Arduino plugin it does not see contents of src folder. I am assuming that it is treated as a separate sketch. What is a proper way to build and run tests?

[edit] Some context (not sure what matters):

  • Our target board is ESP32 DevKit v1
  • Optimally if our developers could run tests on Windows and Linux machines
  • I have not gotten yet to continuous integration. I will start automating once I have any test building and running

[edit 2] I have tried command line tools. Got AUniter running and tried like this (hoping for some automagic done by tools):

me@mypc:~/workspace/Application/Application/tests$ auniter.sh test esp32:/dev/ttyUSB0 TestSomeComponent/

I have tried any sane path combination in include path directive, for example:

#include "SomeComponent.h"
#include "app/SomeComponent.h"
#include "../../src/app/SomeComponent.h"
#include <SomeComponent.h>
#include <app/SomeComponent.h>
#include <../../src/app/SomeComponent.h>

But I keep getting this:

TestSomeComponent:4:42: fatal error: ../../src/app/SomeComponent.h: No such file or directory
1
  • I never came up with an acceptable solution to this, either. Closest I got was mkdir ~/Documents/Arduino/libraries/SomeComponent cp -R src/* ~/Documents/Arduino/libraries/SomeComponent/ and then include <SomeComponent.h> in the test .ino files. That rankles because it means you can't actually unit test a library before installing it. I suspect that's how AUnit/AUniter's author was doing it, though, before they switched away from Arduino IDE/arduino-cli to EpoxyDuino - given all of the AUnit examples use the #include <Foo.h> style. Commented Aug 4, 2021 at 5:03

1 Answer 1

1

I eventually switched to PlatformIO. It took me less than half an hour to rearrange sources, fix some compiler issues, build and flash my device. Tests work really well. You just need to keep tested sources in lib folder. I even got GoogleTest package so I can use gmock in my tests.

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.