Break down tests into categories.
Break down tests into categories to improve maintainability and test granularity. This makes it easier to execute unit tests in CI/CD pipelines. Closes #1054.
This commit is contained in:
47
test_apps/main/test_app_main.c
Normal file
47
test_apps/main/test_app_main.c
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "test_common.h"
|
||||
#include "unity.h"
|
||||
#include "unity_internals.h"
|
||||
#include "unity_test_runner.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#ifndef RELAY_CHN_UNITY_TEST_GROUP_TAG
|
||||
#warning "RELAY_CHN_UNITY_TEST_GROUP_TAG is not defined, using default 'relay_chn'"
|
||||
#define RELAY_CHN_UNITY_TEST_GROUP_TAG "relay_chn"
|
||||
#endif
|
||||
|
||||
void setUp()
|
||||
{
|
||||
g_is_component_initialized = false;
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
// Clean up after each test
|
||||
if (g_is_component_initialized) {
|
||||
relay_chn_destroy();
|
||||
g_is_component_initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
|
||||
// Log general test information
|
||||
ESP_LOGI(TEST_TAG, "Available test count: %d", unity_get_test_count());
|
||||
ESP_LOGI(TEST_TAG, "Running tests for tag: %s", RELAY_CHN_UNITY_TEST_GROUP_TAG);
|
||||
|
||||
if (strncmp(RELAY_CHN_UNITY_TEST_GROUP_TAG, "all", strlen("all")) == 0) {
|
||||
unity_run_all_tests();
|
||||
}
|
||||
else {
|
||||
unity_run_tests_by_tag(RELAY_CHN_UNITY_TEST_GROUP_TAG, false);
|
||||
}
|
||||
|
||||
UNITY_END();
|
||||
ESP_LOGI(TEST_TAG, "All tests complete.");
|
||||
}
|
||||
Reference in New Issue
Block a user