I'm writing code for a microcontroller project using PlatformIO.

I have a couple of classes that I want to write unit tests for. I've not unit tested with pio before so I'm starting with one of the easier classes. I wrote out the start of my test:

#include "PixelRange.h"
#include <unity.h>

void test_forward_incrementation(void)
  PixelRange range = PixelRange(1, 5, 10);
  uint8_t currentIndex = range.getCurrentIndex();

  TEST_ASSERT_EQUAL(5, currentIndex);

int main(int argc, char **argv)
  return 0;

For my class:

#pragma once
#include <Arduino.h>

class PixelRange
  PixelRange() {}
  PixelRange(int rows, int startingIndex, int endingIndex);

  void setReverseIteration(bool reverse);
  uint8_t getNextIndex();
  uint8_t getCurrentIndex();

  int getRowCount();
  int getStart();
  int getEnd();

  bool _iterateInReverse = false;
  uint8_t _iteratorIndex = 0;
  int _rowCount;
  int _start;
  int _end;

  uint8_t forwardIteration();
  uint8_t reverseIteration();

And my platform.ini looks like this:

platform = atmelsam
board = adafruit_trinket_m0
framework = arduino
lib_deps = fastled/FastLED@^3.4.0

platform = native
test_ignore = test_embedded

I wanted to start by running the test in the native environment, but when I run it I get errors saying that I'm missing the Arduino.h file. Even odder, one of the errors is coming from a file that's not even under test.

enter image description here

I'm referring to the calculator example as far as setup and I don't see anywhere in the desktop test where Arduino.h is mocked.

Anyone have an idea of why this would be failing? Here's the full project in case that helps.

  • 1
    I suppose native means on the computer, not on the arduino, and the computer doesn't have a Arduino.h header. Why do you even need it? The uintX_t are defined in <cstdint> header so if it's the only dependency, it should be all to just include it..
    – KIIV
    Aug 14, 2021 at 19:31


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.