1

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) { UNITY_BEGIN(); RUN_TEST(test_forward_incrementation); UNITY_END(); return 0; }

For my class:

#pragma once
#include <Arduino.h>

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

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

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

private: 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:

[env:adafruit_trinket_m0]
platform = atmelsam
board = adafruit_trinket_m0
framework = arduino
lib_deps = fastled/FastLED@^3.4.0

[env:native] 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.

Chris Schmitz
  • 357
  • 6
  • 18

0 Answers0