-
Notifications
You must be signed in to change notification settings - Fork 16
Home
#Motivation No motivation! Use at your own risk.
It is no secret that any production code are preferred to be covered by tests. If you use TDD is your projects - there is no any problem with it, because your code is already covered as mush as it possible. But what if you started to work at project without any test code? Where is the guarantee that any code changing wouldn't lead to the broken project?
In this case some of responsible parts of code must be covered by tests to be sure that any refactoring would not broke it.
If you did use IDE like Intellij IDEA, MSVS or Eclipse, you might notice that pretty feature named 'CodeCoverage' tools or something like this. Standard usage is simple: you run code (tests) and your IDE is colorized with green or black lines pointing at some uncovered parts of code.
QtCreator has not that feature. That's why I decide to write it.
There is tool named Gcov that helps to track code coverage:
Gcov is a source code coverage analysis and statement-by-statement profiling tool. Gcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. Gcov comes as a standard utility with GNU CC (GCC) suite
And frontend to it - lcov:
LCOV is a graphical front-end for GCC's coverage testing tool gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. LCOV supports statement, function and branch coverage measurement.
Okay, let's use it! Here the result:
At this moment only *nix are supported, sorry. Reason is - you have to compile your test project with gcc.
- Download QtCreator source files from here
- Unpack it in some directory. Let's name it
QT_CREATOR_PATH
- Compile QtCreator. There shouldn't be any problem with it. Just:
cd QT_CREATOR_PATH
qmake -r
make
- Clone this repository in some directory. Let's name it
PLUGIN_PATH
- Edit
src/lib/lib.pro
file. You need to changeWORK_DIR
variable to actually QtCreator source directory. - Compile project:
cd PLUGIN_PATH
qmake -r
make
- Install
lcov
. If you use deb-like system, typesudo apt-get install lcov
- After that, run QtCreator from
QT_CREATOR_PATH/bin/qtcreator
- There must be new green button at the left panel. Don't click on it yet.
- (Optional, but recommended) Read gcov and/or lcov start guide.
- Create your test subproject. Add compile flags to it:
LIBS += -lgcov
QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage
- Compile and run test subproject. After that, activate colorizing through
Tools/CodeCoverage/Show code coverage
or typeCtrl+H