There is an Arduino (Uno R4 Minima board) project within VSCode that uses outer libraries like Ethernet.h
and empty stub for unit testing
Build command platformio.exe run --environment uno_r4_minima
compiles depending and my files fine, but test command platformio.exe test
fails.
It requires to include SPI.h
because it mentioned in .pio\libdeps\uno_r4_minima\Ethernet\src\utility/w5100.h
. It is a first weird thing.
Second: after installation missing dependency package test commands fails with errors on standard and third-party libraries
/.pio/libdeps/uno_r4_minima/Ethernet/src/Ethernet.h",
class EthernetServer : public Server {
public:
using Print::write;
...
- 'Server' is not a class or struct name
- type 'arduino::Print' is not a base type for type 'EthernetServer'
etc.
Is there any configuration can change test command behavior? Or maybe I do it completely wrong and some other test approach should be used…
Can you provide a minimal project that reproduces that error?
- You are not including your
ArduinoProxy.h
in the test/test.cpp
file, as thus, PlatformIO’s LDF doesn’t resolve its dependencies correctly. This is expected behavior of the LDF.
- You misspell
Arduino.h
as arduino.h
in that file too, this will cause build failure on Linux / Mac systems
- In your test.cpp you are overwriting the
main()
function, but this being an on-(embedded)-target unit test, it still needs to be an Arduino sketch with setup()
and loop()
. See official example instead.
All in all, if you git apply fix.patch
with
diff --git a/include/ArduinoProxy.h b/include/ArduinoProxy.h
index b46cefc..46bae70 100644
--- a/include/ArduinoProxy.h
+++ b/include/ArduinoProxy.h
@@ -1,7 +1,7 @@
#include <Ethernet.h>
#if defined(ARDUINO) && ARDUINO >= 100
- #include "arduino.h"
+ #include "Arduino.h"
#else
#include "WProgram.h"
#endif
@@ -18,4 +18,4 @@ class ArduinoProxy
IPAddress ip;
unsigned int localPort = 8888;
EthernetUDP udp;
-};
\ No newline at end of file
+};
diff --git a/test/test.cpp b/test/test.cpp
index 9366344..6cce09a 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -1,4 +1,6 @@
#include <unity.h>
+#include <ArduinoProxy.h>
+
void setUp(void) {
// set stuff up here
@@ -8,7 +10,20 @@ void tearDown(void) {
// clean stuff up here
}
-int main( int argc, char **argv) {
+
+void test_calculator_addition(void) {
+ TEST_ASSERT_EQUAL(32, 25 + 7);
+}
+
+void setup() {
+ // NOTE!!! Wait for >2 secs
+ // if board doesn't support software reset via Serial.DTR/RTS
+ delay(2000);
UNITY_BEGIN();
+ RUN_TEST(test_calculator_addition);
UNITY_END();
-}
\ No newline at end of file
+}
+
+void loop() {
+ //Nothing, maybe blink LED
+}
The pio test
command will be able to build the firmware correctly.
1 Like
Thanks, it works
One more question: what is PlatformIO’s LDF?