Add IDE Unit Testing to Your Eclipse IDE – By Itamar Cohen-Ogen
Eclipse IDE is an Open Source project, which allows us to create, edit, build, download and debug our application.
It is the most suitable IDE among various versions, in terms of programming language, target, tool chains and many plugins, to get the most appropriate IDE for our project.
I will focus here on Eclipse based IDE for Embedded Real-Time Firmware applications.
What’s missing here is….a unit testing feature, since unit testing is an important process in the development cycle.
The unit testing phase in the development cycle is necessary to improve our product quality and shorten the development cycle time.
By adding unit testing code, we can find potential bugs in our code before even running it on target.
Unit testing to IDE, is added value to product development, since it is integrated and easy to use – no excuses are raised!
Why is it missing?
One major problem with the Eclipse-based IDEs, is that they are missing a unit testing tool/feature for C/C++ Development Tooling (CDT).
Thus, in Eclipse IDE, the developers need to find complementary unit testing tools for embedded applications.
Therefore, we need to write specific code, mostly undocumented, to perform unit testing – creating our own unit testing engine.
This is wrong and inefficient!
What can be done?
Searching for Eclipse IDE unit testing tools, shows that there some unit testing tools that can be plugged-in as part of the IDE.
Since the Eclipse Juno version, the CDT already contains unit testing library support.
The unit testing libraries that are supported are:
Let me show you how!
I’m basing my technical “how to” on a tutorial that explains how to use the unit testing plugin in Eclipse IDE:
Installing unit testing in Eclipse Juno and above:
- Install the CDT (Help->Install Software->CDT) optional C/C++ Unit Test support
- Create a new Runner using ‘Run As -> Run Configurations -> C/C++ Unit Test
- Choose ‘Google Tests Runner’ for ‘Tests Runner’ in the ‘C/C++ Testing’ tab
- Choose your testing project executable in the ‘Main’ tab
- Run it, and the ‘C/C++ Unit’ view shows up after (rebuild and) execution
CDT 8.1 Unit Testing supports the following frameworks:
Quick screenshot from the link: http://feelings-erased.blogspot.co.il/2012/07/eclipse-juno-has-landed-with-unit.html:
First, enable C++ Unit Testing view:
The main screen of the feature should be shown:
Here is an example with Google Test:
* Created on: 27 June 2018
* Author: Itamar
using namespace std;
virtual File* getData() = 0;
virtual void write(File* data) = 0;
auto source = mocks.InterfaceMock<Source>();
auto destination = mocks.InterfaceMock<Destination>();
auto file = mocks.Mock<File>();
Create a new run configuration and execute it.
Running this example in CDT Unit Test runner, requires you to create a new Run Configuration.
Just right-click on the project, select Run As->Run Configurations and double click C++ Unit.
On the C/C++ Testing tab, select Google Test Runner from the dropdown list and click Run.
If everything goes well, you should see the following screen:
Unit testing needs to be integrated in IDE, to make it simple to use during the development cycle process.
The use of unit testing might shorten your development time and maintenance of your product.
To add unit testing as part of your development process, you first need to declare a pilot project to check which tool is best to use and fully integrated in IDE.