The question is maybe not explicit enough.
I'm trying to write tests for an Arduino program, using VSCode with Platformio.
Here is an example of a function I want to test:
#include "flash.h"
#include <Arduino.h>
void flashXTimes(
uint8_t LEDPin,
uint16_t numberOfFlashes,
uint16_t onDuration,
uint16_t offDuration)
{
for (uint16_t i = 0; i < numberOfFlashes; i++)
{
digitalWrite(LEDPin, HIGH);
delay(onDuration);
digitalWrite(LEDPin, LOW);
delay(offDuration);
}
}
I want to check that when I call this function with numberOfFlashes 3, it will actually flash 3 times. Sure the code is so easy that tests aren't really needed, but I want to do them anyway.
So ChatGPT gave me a hint of using a mock digital write
static uint32_t digitalWriteCalls = 0;
void digitalWriteMock(uint8_t pin, uint8_t val) {
digitalWriteCalls++;
}
but then told me to digitalWrite = &digitalWriteMock;
which would work fine in Python, but not in C++.
By following the Platformio testing guide using Unity, I got tests going, but nothing meaningful.
I'd appreciate some help in getting started with testing in C++/Arduino