-1

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.

Matias
  • 539
  • 5
  • 28
  • Non-Object oriented code is probably a poor subject for unit testing. The problem is you can't provide mocks very well for required interfaces. See also [Mocking free function](http://stackoverflow.com/questions/28392277/mocking-free-function) – πάντα ῥεῖ Feb 20 '16 at 15:00
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – David van Driessche Feb 20 '16 at 16:49
  • Hi David, I changed the question a little bit but really I don't have tried anything so far because I couldn't find an example of Unit Testing done to non object oriented code in C++.. – Matias Feb 20 '16 at 17:19

1 Answers1

3

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).

lisyarus
  • 15,025
  • 3
  • 43
  • 68