Search code examples
c++unit-testingstructured-programming

Unit Testing NON-Object oriented programming


We have code which was written using Non-Object oriented programming and we would like to do unit testings. I've seen easy Unit Testing over Object Oriented Code in Visual Studio but I've not found a way to test when I don't have classes and objects..

We are using Visual Studio 2008 and code is written in C++ with no classes, just functions. Is it possible to apply Unit Testing to non-object oriented code? test Thank you,

Matias.


Solution

  • Many unit-testing frameworks for C++ are OOP-agnostic (for example, Boost Test, Google Test or Qt Test). Each test is simply some code with assertions on some conditions (for example, assertions that a function returned what it was expected to).

    However, such testing is usually easy only provided that your functions are free (that is, do not use some global state, return the same result if called with the same arguments, and can be called function as in mathematics).