starting with component unit testing (running on device)

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2024-05-17 12:03:16 +02:00
parent 05f8519864
commit 0944d29597
18 changed files with 127 additions and 13 deletions

16
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,16 @@
# This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
# Include the components directory of the main application:
#
set(EXTRA_COMPONENT_DIRS "../components")
# Set the components to include the tests for.
# This can be overriden from CMake cache:
# - when invoking CMake directly: cmake -D TEST_COMPONENTS="xxxxx" ..
# - when using idf.py: idf.py -T xxxxx build
#
set(TEST_COMPONENTS "logger" CACHE STRING "List of components to test")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(component_unit_test)

6
test/Makefile Normal file
View File

@@ -0,0 +1,6 @@
test:
@echo "Running tests..."
@idf.py fullclean build
pytest
.PHONE: test

2
test/main/CMakeLists.txt Normal file
View File

@@ -0,0 +1,2 @@
idf_component_register(SRCS "components_test.c"
INCLUDE_DIRS ".")

View File

@@ -0,0 +1,16 @@
#include <stdio.h>
#include <string.h>
#include "unity.h"
static void print_banner(const char* text);
void app_main(void) {
print_banner("Running all the registered tests");
UNITY_BEGIN();
unity_run_all_tests();
UNITY_END();
}
static void print_banner(const char* text) {
printf("\n#### %s #####\n\n", text);
}

6
test/pytest_unittest.py Normal file
View File

@@ -0,0 +1,6 @@
import pytest
from pytest_embedded import Dut
def test_unit_test(dut: Dut) -> None:
dut.expect("0 Failures")
dut.expect("Returned from app_main")

2
test/sdkconfig.defaults Normal file
View File

@@ -0,0 +1,2 @@
# disable watchdog
CONFIG_ESP_TASK_WDT_EN=n