I want to write unit tests for my programs in platformio for esp32. I use Arduino framework. I have a ESP Prog ( https://www.digikey.com/en/products/detail/espressif-systems/ESP-PROG/10259352 ) . I used zadig to change ftdi driver as mentioned here : Zadig Driver Installation Guide
I can debug my programs through jtag port but when I run Test command every thing halt after platformio shows “If you don’t see any output for the first 10 secs, please reset board (press reset button)” .
I used a simple sample as following:
main :
#include <Arduino.h>
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Hello world!");
delay(1000);
}
test program :
#include <Arduino.h>
#include <unity.h>
String STR_TO_TEST;
void setUp(void) {
// set stuff up here
STR_TO_TEST = "Hello, world!";
}
void tearDown(void) {
// clean stuff up here
STR_TO_TEST = "";
}
void test_string_concat(void) {
String hello = "Hello, ";
String world = "world!";
TEST_ASSERT_EQUAL_STRING(STR_TO_TEST.c_str(), (hello + world).c_str());
}
void test_string_substring(void) {
TEST_ASSERT_EQUAL_STRING("Hello", STR_TO_TEST.substring(0, 5).c_str());
}
void test_string_index_of(void) {
TEST_ASSERT_EQUAL(7, STR_TO_TEST.indexOf('w'));
}
void test_string_equal_ignore_case(void) {
TEST_ASSERT_TRUE(STR_TO_TEST.equalsIgnoreCase("HELLO, WORLD!"));
}
void test_string_to_upper_case(void) {
STR_TO_TEST.toUpperCase();
TEST_ASSERT_EQUAL_STRING("HELLO, WORLD!", STR_TO_TEST.c_str());
}
void test_string_replace(void) {
STR_TO_TEST.replace('!', '?');
TEST_ASSERT_EQUAL_STRING("Hello, world?", STR_TO_TEST.c_str());
}
void setup()
{
delay(10000); // service delay
UNITY_BEGIN();
RUN_TEST(test_string_concat);
RUN_TEST(test_string_substring);
RUN_TEST(test_string_index_of);
RUN_TEST(test_string_equal_ignore_case);
RUN_TEST(test_string_to_upper_case);
RUN_TEST(test_string_replace);
UNITY_END(); // stop unit testing
}
void loop()
{
}
output:
Processing test_blink in esp32doit-devkit-v1 environment
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Building & Uploading...
Open On-Chip Debugger v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
debug_level: 1
adapter speed: 20000 kHz
WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
adapter speed: 5000 kHz
Error: libusb_open() failed with LIBUSB_ERROR_NOT_SUPPORTED
** Programming Started **
** Programming Finished in 4396 ms **
** Verify Started **
** Verify OK **
** Programming Started **
** Programming Finished in 1225 ms **
** Verify Started **
** Verify OK **
** Programming Started **
** Programming Finished in 906 ms **
** Verify Started **
** Verify OK **
** Programming Started **
** Programming Finished in 1017 ms **
** Verify Started **
** Verify OK **
shutdown command invoked
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)