简体   繁体   English

代码行VS指令在测量代码质量时

[英]Lines of Code VS Instructions while measuring code quality

I have a projet composed of numerous modules. 我有一个由众多模块组成的项目。 I am running both JaCoCo for unit tests coverage and Sonar for code quality. 我正在运行JaCoCo进行单元测试覆盖,而Sonar运行代码质量。

For a technical reason, I can't use JaCoCo reports for one of my modules (GWT erases the target folder and I couldn't go past this issue yet). 由于技术原因,我不能将JaCoCo报告用于我的一个模块(GWT擦除了target文件夹,我还没有通过这个问题)。

Let's say I have 8 modules, from 1 to 8. One of them is for domain objects only, so I don't want to cover it with my tests. 假设我有8个模块,从1到8.其中一个仅用于域对象,所以我不想用我的测试来覆盖它。 Same goes for another one, dedicated for auto-generated classes. 另一个专用于自动生成的类。

JaCoCo runs on 5 modules, and Sonar on 6 modules. JaCoCo运行5个模块,Sonar运行6个模块。

The total instructions shown by JaCoCo is 145k. JaCoCo显示的总指令是145k。

Sonar shows a total of 75k LOC. 声纳显示总共75k LOC。


Aren't they quite the same ? 他们一样吗? Did I miss something ? 我错过了什么 ? Is JaCoCo taking in account the whole project whatever reports I feed him ? JaCoCo是否考虑了整个项目,无论我喂他什么报告? What can possibly explain this gap in measurement ? 什么可以解释这种测量差距?

Aren't they quite the same ? 他们不一样吗?

Not at all. 一点也不。

From http://www.jacoco.org/jacoco/trunk/doc/counters.html : 来自http://www.jacoco.org/jacoco/trunk/doc/counters.html

The smallest unit JaCoCo counts are single Java byte code instructions. JaCoCo计数的最小单位是单个Java 字节代码指令。

comparison of "instructions" with "lines of code" is like comparison of apples and oranges - they don't represent the same thing. “指令”与“代码行”的比较就像苹果和橙子的比较 - 它们并不代表相同的东西。 Single line of code usually contains many bytecode instructions. 单行代码通常包含许多字节码指令。

For example 例如

System.out.println("Hello, World!");

is a single line, but 3 bytecode instructions as can be seen using javap (Java Class File Disassembler) : 是一行,但使用javap (Java类文件反汇编程序)可以看到3字节码指令:

     0: getstatic     #2                  // Field java/lang/System.out:Ljava/io/PrintStream;
     3: ldc           #3                  // String Hello, World!
     5: invokevirtual #4                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V

BTW JaCoCo also counts lines. BTW JaCoCo也统计线路。 But while comparing this one with LoC in SonarQube, please take into account that algorithms of calculation are different - JaCoCo computes this number by analyzing information recorded by compiler in bytecode, while SonarQube computes this number by analyzing source code. 但是在将这个与SonarQube中的LoC进行比较时,请考虑计算算法是不同的 - JaCoCo通过分析编码器在字节码中记录的信息来计算这个数字,而SonarQube通过分析源代码来计算这个数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM