I am running a bunch of embedded tests on my stm32 and for clarity’s sake, I want to split my tests over multiple tests in logical chunks.
What I am using in my native unittests is split the tests into multiple files, each having theyr own namespace, and from the main test file, call the main functions from each namespace. I can do the same in embedded tests by substiuting the main function with setup
obviously like this:
test_main.cpp
#if defined(ARDUINO) && defined(UNIT_TEST)
#include <Arduino.h>
#include "test_a.hpp"
#include "test_b.hpp"
void setup() {
test_a::setup();
test_b::setup();
}
void loop() {
}
#endif
In test_a.hpp:
#include "unity.h"
namespace test_a {
void test_something() {
TEST_ASSERT_EQUAL(1, 1);
}
void setup() {
UNITY_BEGIN();
RUN_TEST(test_something);
UNITY_END();
}
void loop() {
}
}
And the same code in test_b.hpp, just renaming the namespace to test_b.
This pattern works fine for native tests, but in embedded tests, it results in only one set of tests to be run:
Starting execution at address 0x08000000... done.
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)
test/test_sample/test_a.hpp:8:test_something [PASSED]
-----------------------
1 Tests 0 Failures 0 Ignored
I can work around it by calling UNITY_BEGIN
/UNITY_END
in test_main.cpp and removing it from the other setup functions, but then all tests are reported as coming from test_main.cpp, and I can’t see the original file anymore where the test was defined. Like this:
Starting execution at address 0x08000000... done.
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)
test/test_sample/test_main.cpp:8:test_something [PASSED]
test/test_sample/test_main.cpp:8:test_something [PASSED]
-----------------------
2 Tests 0 Failures 0 Ignored
Is there any good way I can split my embedded tests over multiple files like this? Of course I can make the names of each test unique across all files, but that is what namespaces are meant for, and would make test function names unnecessarily long.