Professional Documents
Culture Documents
Lab Exercise
Software Metrics
1 Introduction
This is not a full, normal, lab where you are supposed to reflect over the results etc. Instead, this lab will
give you hands-on guidelines for some basic metrics. The measurements we will do are counting source
lines of code (SLOC), test coverage, duplicated code, and code complexity. Software metrics in general
and what measurements should be made to get reliable results is hard, and the actual correlation between
the metrics and what we want to know, for example the code quality, is not 100. However, ”You cannot
control what you cannot measure” (DeMarco) is also true.
3 Test Coverage
You should use the tool EClEmma which is an Eclipse plugin. You need to install the plug in:
• In Eclipse select the menu Help/Install new software
• Add software from http://update.eclemma.org/
4 Duplicated Code
Here we use the tool PMD, also run from the command line. See https://sourceforge.net/projects/pmd
Installed at /usr/local/cs/EDAF45/pmd/bin/pmd (or just pmd if you run initcs once first)
1
How much code (how many tokens) needed to be equal to be counted as ”duplicated code” is set as
input. Use 50 tokens. The command will then be:
pmd cpd --minimum-tokens 50 --files src
where ”src” is your directory containing the source code
A hint is then to use ”grep” to find relevant info, e.g.
• ... |grep ”Found a” (all found and how long they are)
• ... |grep ”Found a” — wc (the number of duplicates)
5 Code Complexity
We will use two metrics for complexity, ”Cyclomatic complexity” and ”NPath”.
Cyclomatic complexity is a software metric (measurement), used to indicate the complexity of a pro-
gram. It is a quantitative measure of the number of linearly independent paths through a program’s
source code. It was developed by Thomas J. McCabe, Sr. in 1976.
Read more at https://en.wikipedia.org/wiki/Cyclomatic complexity.
The NPath complexity of a method is the number of acyclic execution paths through that method.