Missing Arduino.h for platform Native


today I started testing PioPlus Unit Test feature on a ESP8266 based project. While it builds and run the tests succesfully for the embbeded flatform, it gives me errors related to Arduino.h: no such file or directory when trying to build for native platform. The output i get when running pio test -e native --verbose is as follows:

PlatformIO Plus (https://pioplus.com) v0.6.10
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

 [test::test_1] Building... (1/2)

[04/06/17 14:30:34] Processing native (platform: native, piotest: test_1)

Verbose mode can be enabled via `-v, --verbose` option
Collected 13 compatible libraries
Looking for dependencies...
Library Dependency Graph
|-- <AsyncMqttClient> v0.5.0
|   |-- <ESPAsyncTCP> v1.0.1
|-- <Time> v1.5
|-- <Homie> v2.0.0
|   |-- <ArduinoJson> v5.8.3
|   |-- <AsyncMqttClient> v0.5.0
|   |   |-- <ESPAsyncTCP> v1.0.1
|   |-- <Bounce2> v2.1
|-- <Nanopb> v0.3.9-dev
|-- <RTC> v2.0.0
|-- <ArduinoJson> v5.8.3
|-- <Crc16>
|-- <ProtoBuf>
|   |-- <Nanopb> v0.3.9-dev
Compiling .pioenvs\native\src\BLENordicNode\BLENordicNode.o
Compiling .pioenvs\native\src\BLENordicNode\Encoders\BaseEncoder.o
Compiling .pioenvs\native\src\BLENordicNode\Encoders\Encoder.o
In file included from src\BLENordicNode\BLENordicNode.cpp:8:0:
src\BLENordicNode\BLENordicNode.hpp:14:21: fatal error: Arduino.h: No such file or directory
compilation terminated.
Compiling .pioenvs\native\src\BLENordicNode\Encoders\RelayEncoder.o
In file included from src\BLENordicNode\Encoders\BaseEncoder.hpp:11:0,
from src\BLENordicNode\Encoders\BaseEncoder.cpp:8:
src\BLENordicNode\Encoders\Encoder.hpp:11:21: fatal error: Arduino.h: No such file or directory
compilation terminated.
*** [.pioenvs\native\src\BLENordicNode\BLENordicNode.o] Error 1
*** [.pioenvs\native\src\BLENordicNode\Encoders\BaseEncoder.o] Error 1
In file included from src\BLENordicNode\Encoders\Encoder.cpp:8:0:
src\BLENordicNode\Encoders\Encoder.hpp:11:21: fatal error: Arduino.h: No such file or directory
compilation terminated.
*** [.pioenvs\native\src\BLENordicNode\Encoders\Encoder.o] Error 1
In file included from src\BLENordicNode\Encoders\RelayEncoder.hpp:11:0,
from src\BLENordicNode\Encoders\RelayEncoder.cpp:8:
src\BLENordicNode\Encoders\Encoder.hpp:11:21: fatal error: Arduino.h: No such file or directory
compilation terminated.
*** [.pioenvs\native\src\BLENordicNode\Encoders\RelayEncoder.o] Error 1
 [ERROR] Took 1.03 seconds

Environment nodemcuv2           [SKIP]
Environment SmartScanner        [SKIP]
Environment MOB                 [SKIP]
Environment MOB_BOOTSTRAP       [SKIP]
Environment native              [ERROR]
 [ERROR] Took 1.04 seconds

Any input would be much appreciated.


Although the methods referenced there seem sound, I can’t see why the files acctually generating errors are getting compiled in order to run the single test case I’ve implemented, to which there are no dependencies.

The project I’m trying setup with unit tests has by now a fairly large codebase, and having to mock every single missing library before being able to run any tests would generate a unecessary effort.

Is there a way to tell pio test to run a single test? If so, would it prevent it from trying to compile the entire codebase before running the tests?

1 Like

Sure, pio test -e nodemcuv2 -e bla-bla...

I actually meant a single test, really, like if there’s:

 |--- test_packetHandler
 |--- test_protocolBuffer
 |--- test_I2C_temp

it’s certainly possible to run only test_packetHandler by using --ignore "test_protocolBuffer" "test_I2C_temp" (btw is there any more straightforward way of doing this?). However that doesn’t seem to convince GCC to compile only test_packetHandler dependencies.

In the log above for exemple:

*** [.pioenvs\native\src\BLENordicNode\Encoders\BaseEncoder.o] Error 1

refers to a object file that doesn’t need to be linked to run the test I wanted to run, however it’s breaking the compilation.

1 Like

Have you read this?

Well, yes. From my understanding of this documentation there’s the option to ignore specific test cases using the flags -i or --ignore, or using the test_ignore option on the environment configuration. However there’s no option to do the oposite: directly specify a single test to be run. Am I wrong? If I’m not, it seems not too practical when the amount of tests grows.

But the real issue to me seems to be with the way the test target compile things before running tests. For this specific project I’m working on there’s already a pretty extensive and untested codebase. While I’m testing and altering stuff in a single unit, it might break things in other units. As as every single source file in the project seems to be compiled before runnning each test, when somethings is altered in a specific unit, causing other unit’s compilation to break, i’ts impossible to run the tests, at least until those other units are fixed, and that’s not practical at all.

1 Like

Thanks, I’ve got you now. Yes, you can’t run specific test directly from CLI. Please open a feature request here and we will implement this use case. Nevertheless, you can use Glob syntax for test name and exclude a bunch of tests via test_*.

You can filter source code per build environment. See

Thanks a lot for your feedback!

Perfect, opened issue here: #934.

Also, it was possible to run the tests on platform native using the src-filter tag as follows:

src_filter=-<*> +<../lib/ProtoBuf/> +<BleNordicNode/PacketUtils.hpp> +<BleNordicNode/PacketUtils.cpp>

But it means that before running each test it’s necessary to change the src_filter, not really practicall.
I’m not familiar with SCONS, but I’m pretty sure ina Make environment it would be possible to determine source dependencies to avoid this. Is there any workaround?

@ivankravets I added a feature request to add support for CMock. Would that be possible sometime soon?

By now I’m able to generate mocks for the libs i need to, directly calling cmock. I’ve set i to create all the mocks in a mock folder placed in the project’s root.

But I can’t understang how I could possibly instruct the build system to link my fake lib during compile time, like Ceedling does.


  • Need to mock Timelib.h since it breaks compilation due to some header included inside TimeLib.h not being found.
  • Create mock/Time_ID44_Mock/TimeLib.h using CMock
  • Add lib_ignore= Time to native build environment.
  • Add src_filter= +<../mock/Time_ID44_Mock/> to native build environment.

But still pio test build fails due to some weird error. Is there something I’m missing?

How about to try the next?

  1. Set lib_compat_mode = strict
  2. Add library.json with platform: "native" to Time_ID44_Mock?