Adding unit tests to a legacy, plain C project
Posted
by
Groo
on Programmers
See other posts from Programmers
or by Groo
Published on 2011-08-25T06:49:18Z
Indexed on
2012/04/12
17:41 UTC
Read the original article
Hit count: 283
The title says it all. My company is reusing a legacy firmware project for a microcontroller device, written completely in plain C.
There are parts which are obviously wrong and need changing, and coming from a C#/TDD background I don't like the idea of randomly refactoring stuff with no tests to assure us that functionality remains unchanged. Also, I've seen that hard to find bugs were introduced in many occasions through slightest changes (which is something which I believe would be fixed if regression testing was used). A lot of care needs to be taken to avoid these mistakes: it's hard to track a bunch of globals around the code.
To summarize:
- How do you add unit tests to existing tightly coupled code before refactoring?
- What tools do you recommend? (less important, but still nice to know)
I am not directly involved in writing this code (my responsibility is an app which will interact with the device in various ways), but it would be bad if good programming principles were left behind if there was a chance they could be used.
© Programmers or respective owner