Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to add a couple of tests to a legacy C project. The project basically consists of a command line tool that prints something to stdout every time an event happens. Now, since writing unit tests would be pretty hard given the fact that the modules are pretty tight coupled, I am trying to write some functional tests in order to validate the current behaviour and then I'll go on splitting the modules so I can unit test them.

Does it make sense to have the testing framework something like a few Python scripts (keep in mind that the project is pure C) that handles all the functional tests? Basically, Python should call my command line tool, fake its input and expect a valid output.

share|improve this question

migrated from Feb 13 '12 at 2:26

This question came from our site for professional and enthusiast programmers.

Slightly related: I'd suggest a look at Working Effectively with Legacy Code, by Michael Feathers, which contains sound advice and patterns to deal with testing, extending, refactoring legacy projects. – Giulio Piancastelli Sep 6 '11 at 22:42
Thanks @Giulio, I know about the book, I was looking for more hands-on experience with this approach. – hyperboreean Sep 6 '11 at 22:47

Yes it does and is a wise Idea.

You can also go in the details using Cython and calling some of the legacy C functions.

share|improve this answer


If the tests use the application as a black box, through the command line, then they don't need to be in the same language as the application. They can be in a language that is best suited for writing the tests.

Scripting languages, such as Python or Ruby, are generally a good fit for text parsing and calling command line applications, whereas with C it would be much harder. They also have good testing tools to help in writing those tests.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.