Hello everybody!
I want to add unit tests to my project. I followed the different guides available on the official documentation, but nothing worked.
I thought that maybe, the configuration of my project was not correct, so I tried to setup the most simple project anyone can think of: a hello world. Turns out, it doesn’t work either.
This is the structure of my “test” project, created with pio init --ide vim
:
.
├── include
│ └── README
├── lib
│ └── README
├── platformio.ini
├── src
│ └── main.cpp
└── test
├── README
└── main.cpp
Here is the plateformio.ini
:
[env:nano33ble]
platform = nordicnrf52
board = nano33ble
framework = arduino
My src/main.cpp
is very simple:
#include <Arduino.h>
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hi there");
delay(1000);
}
Finally, here is my test/main.cpp
:
#include <Arduino.h>
#include <unity.h>
void simple_test(void) {
TEST_ASSERT_EQUAL(33, 33);
}
void setup() {
delay(2000);
UNITY_BEGIN();
RUN_TEST(simple_test);
UNITY_END();
}
void loop() {
delay(1000);
}
If I run pio run
and monitor the serial of my arduino, I can read “Hi there” every second. On the other hand, if I run pio test
I have a bunch of warnings such as:
/home/furnost/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/furnost/.platformio/packages/framework-arduino-mbed/variants/ARDUINO_NANO33BLE/libs/libmbed.a(unity.o):(.rodata.UnityStrErrDouble+0x0): multiple definition of `UnityStrErrDouble'; .pio/build/nano33ble/libUnityTestLib.a(unity.c.o):(.rodata.UnityStrErrDouble+0x0): first defined here
/home/furnost/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: /home/furnost/.platformio/packages/framework-arduino-mbed/variants/ARDUINO_NANO33BLE/libs/libmbed.a(unity.o):(.rodata.UnityStrErrFloat+0x0): multiple definition of `UnityStrErrFloat'; .pio/build/nano33ble/libUnityTestLib.a(unity.c.o):(.rodata.UnityStrErrFloat+0x0): first defined here
/home/furnost/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: warning: size of symbol `Unity' changed from 132 in .pio/build/nano33ble/libUnityTestLib.a(unity.c.o) to 160 in /home/furnost/.platformio/packages/framework-arduino-mbed/variants/ARDUINO_NANO33BLE/libs/libmbed.a(unity.o)
And an error message:
collect2: error: ld returned 1 exit status
*** [.pio/build/nano33ble/firmware.elf] Error 1
In my real project, I am using different “libraries”: Arduino.h
, ArduinoBLE.h
, rtos.h
and mbed.h
. I don’t know if it helps but…
I am not quite sure about what to do, nor do I know what causes the problem. Any help will be greatly appreciated!
Furnost