Part 0: Setting up the tools
There several frameworks we can use out there to test our code but we going to choose Ceedling since it was created explicitly to cover embedded needs. besides is relatively easy to use well documented and supported,
There several frameworks we can use out there to test our code but we going to choose Ceedling since it was created explicitly to cover embedded needs. besides is relatively easy to use well documented and supported,
It is really easy to create unit tests in general but it will take some practice to master this new concept, if functions has parameters and return values, then things are straight forward , like the first example. here are a few more examples
This time we are going to refer a global variables like the ones who has an external reference in our codes, like in this example variable subs, that later is use in function subtraction
Static function are those you want to use only for internal driver use, and therefore their prototypes will never be written in
State machines is like a lot for embedded software, and for sure can be tested in all of their forms, but lest begin with the most simple example. A state machine that with three states that only moves the next state on each one.
Unit testing with hardware with mock functions is really neat it allows you to test your upper layers without the need to have a hardware, but what if we are actually develop a low level driver that interact directly with the microcontroller registers,
The goal of your unit test should be to test your code at a 100%, but his does not mean writing ALL the possible test cases for every single function, that will be incredible demanding and not really worthy the effort.
According to the previous code on dummy.c our testing file should be similar as the previous one, we must mock the stm32g0xx_hal_adc.h, and call all the corresponding mock version use by the code under test. In this particular case we use ExpectAndReturn