You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
#include"seatest.h"//// create a test...//voidtest_hello_world(){char*s="hello world!";assert_string_equal("hello world!",s);assert_string_contains("hello",s);assert_string_doesnt_contain("goodbye",s);assert_string_ends_with("!",s);assert_string_starts_with("hell",s);}//// put the test into a fixture...//voidtest_fixture_hello(void ){test_fixture_start();run_test(test_hello_world);test_fixture_end(); }//// put the fixture into a suite...//voidall_tests(void ){test_fixture_hello(); }//// run the suite!//intmain(intargc,char**argv ){returnrun_tests(all_tests);}
Fixtures
In many xUnit style testing frameworks, tests and testfixtures are automatically discovered. So all you do is write your test, or fixture, and they are automatically run. Which is great! You never forget to include a test. However in C, there is no language mechanism to do this. (Some of the C unit testing frameworks make use of something like python to find the tests automatically)
So Seatest requires you to explicitly register all your tests and fixtures. If you are in the habit of "red green refactor", this limitation shouldn't be too much of a problem. The main reason for this is that the framework needs to be easily used in embedded environments / compilers / IDEs. The current prime target being PICs and the MPLAB IDE. So things are kept to pretty vanilla C code.
SeaTest? was built to support embedded development using a dual compiler approach. This approach involves developing the bulk of the code / tests in a Rich C development environment, like Visual Studio, and then cross compiling with the more limited embedded C compiler to check the unit tests also run on the target device.
One of the big factors was to make sure seatest didn't use any dynamic memory allocation (like malloc, etc). Or store a big list of tests in some sturcture. All the test fixtures and tests are created through the structure of the code itself. Making it simple, quick, and very straightforward.
The general approach to fixtures generally looks like the following :-
Note, this section is currently getting built up and might seem a bit incomplete at times . It needs building into a full tutorial and a description on how to do embedded C unit testing
Download the source code
include "seatest.c" and "seatest.h" in your project, make sure the .h is in a directory your compiler will find when including headers.
create a function called something like "alltests" which will combine all your test suites together
In your main create the test runner
Create a test suite
Create tests
Run
Abort test on first test failure
Normally Seatest will run all asserts in a test no matter whether they pass or fail. If you want the test to abort on the first failure then set the #define ABORT_TEST_IF_ASSERT_FAIL.