Start unit testing in C++ with Isolator++!
Isolator++ enables easy unit testing of existing and new C++ code.
Unit testing in C++ is a hassle. But once you've decided to do it, you're faced with the main problem of unit testing in any language - you can't unit test the code, because it depends on classes and external resources. Without tests, the code is vulnerable to regression bugs, and therefore you usually don't touch it, and are scared just from the thought.
Isolator++ allows you change the behavior of dependencies in your code, without changing it. You build a test application using the framework of your choice (GoogleTest, UnitTest++, CppUnit, etc.), include Isolator++ header file, link with the Isolator++ library and then use the Isolator++ APIs in your tests to change the behavior of method calls to dependencies. All this without changing their code. Isolator++ contains innovative features to keep your tests short, readable and robust.
Here's a short example. Let's look at our Product class' method IsExpired:
struct tm * now;
now = localtime(&rawtime);
if (now->tm_year > 2017)
The method has a dependency on the time when the code is run. How can we test the result for a year after 2017?
With Isolator++'s macros (in red), you can simply change the behavior of the localtime method:
// Prepare a future time construct
tm* fakeTime = new tm();
fakeTime->tm_year = 2018;
// Fake the localtime method
// Replace the returned value when the method is called
// with the fake value.
When the IsExpired method is called, the call to localtime is ignored, and then returns the value we supply - our future time construct.
Without changing the code, we actually we able to simulate the localtime to check a second path in the code.
To learn more about how to use Isolator++, check out the next chapters: