One of the new features introduced in VisualGDB 5.2 is the seamless integration of C++ unit testing frameworks into Visual Studio. VisualGDB supports the CppUTest and GoogleTest frameworks for Linux, Android and Embedded projects out-of-the-box and also comes with a powerful customization mechanism that allows describing any other test framework in a way that will allow VisualGDB to discover and run tests from it with just a few mouse clicks.
Let’s look into the new unit test system in detail.
This one is really straight-forward. We have simply added a new option called “Unit test project” to Embedded, Linux and Android project wizards. It automatically downloads the selected test framework (CppUTest and GoogleTest are supported out-of-the-box) and creates a project with a few predefined tests demonstrating how to use the selected framework:
On Android VisualGDB offers a choice between running the C++ tests inside a Java App (the main activity will run the tests and exit the app) or in a stand-alone Android executable that is very lightweight, quick to build and deploy and does not require the Java layer:
Running and debugging tests
VisualGDB transparently integrates the C++ testing functionality into the regular Visual Studio GUI (supported starting from Visual Studio 2012), so you can use the regular Test Explorer window and the Test menu to browse, run or debug your tests. Like in C# tests, the failed test will display what triggered the failure along with a call stack that will help you quickly pinpoint the cause of the failure.
We’ve also made it very easy to debug your tests: just select one or more failed tests in the Test Explorer, right-click and select “Debug”. This will automatically launch debugging of the selected tests and once a failure is reported by the test, VisualGDB will intercept it and allow you to investigate:Once you click “Break”, VisualGDB will stop the debug session at the time when the error happened allowing you to investigate what is going on. If the preprocessor macros used by the test framework make things unclear, you can use the “Preprocess selected lines” command to quickly expand them in-place:
To support unit testing on very small embedded devices that don’t have a lot of resources we have created a miniature testing framework that uses the CppUTest syntax and minimizes the amount of code that needs to be run on the device. It has a FLASH memory footprint of less than 10KB and is supported out-of-the-box by VisualGDB:
The VisualGDB test system is designed to be easily extendable to support other test frameworks and platforms. This post gives a detailed explanation of the related settings that allow using VisualGDB with any other C++ test framework.
You can download the latest VisualGDB version with unit test support on the download page.