I am currently working on a code base, that has never had any unit tests written on it. It has been written for a 16-bit Embedded processor, and I would like to start to add unit tests for all the code that I write, at a minimum and then extend this to other parts of the code.
My problem with this is, I have found that each module (.c file) at the application level, seems to be tightly coupled to other C files in the project. For any given file, this may be anywhere from 2-10 files down.
- How do I start to write the unit tests?
- What are the best/quick/most efficient ways to remove this tight coupling?
- Also the unit tests will be run on the PC, (32 bit) and the embedded code is for a 16-bit processor. How do I ensure this is taken care of when porting the code to the PC?
Regarding #3 – making sure it is portable to PC, here’s the strategy I use:
First, go through the embedded code and change any ‘int’ or ‘unsigned long’ to ‘int16’
or ‘uint32’ (or whatever convention you choose).
Wrap the section in the embedded header where you define the types inside a condition:
create a “PC_Types.h” file which defines the same types for the PC.
In the PC project, create a wrapper for each embedded c file, which contains the following:
By wrapping every file, you have all the coupled functions available as needed. #including the original source file in your wrapper file allows you to drop in updates to the embedded code directly from your source control system without any modification. Adding the test functions after the included source gives the test code full access to all the module’s functions, even if they don’t have a public header.