eclemma

使用 EclEmma 进行覆盖测试

空扰寡人 提交于 2020-11-19 00:14:48
现在 IT 开发人员比以往任何时候都更加关注测试的重要性,没有经过良好测试的代码更容易出问题。在极限编程中,测试驱动开发已经被证明是一种有效提高软件质量的方法。在测试驱动的开发方式中,软件工程师在编写功能代码之前首先编写测试代码,这样能从最开始保证程序代码的正确性,并且能够在程序的每次演进时进行自动的回归测试。测试对于软件产品的成败起着至关重要的作用,在极限编程领域,甚至有人提议任何未经测试的代码都应该自动从发布的产品中删除。作者并不确信这个观点是正确的,但是测试本身的质量确实是一个需要高度关注的问题。测试的覆盖率是测试质量的一个重要指标,我们需要工具来帮助我们进行对软件测试覆盖的考察。 EclEmma 就是这样一个能帮助开发人员考察测试覆盖率的优秀的 Eclipse 开源插件。EclEmma 在覆盖测试领域是如此的优秀,以致于它在过去不久的 2006 年成为了 Eclipse Community Awards Winners 决赛选手。虽然最后 Eclipse Checkstyle Plugin 取得了 Best Open Source Eclipse-based Developer tool 的称号,但我们也可以由此看到 EclEmma 对开发人员的帮助是巨大的(Eclipse Community Award 的具体信息可以参阅 参考资源 )。 提到 EclEmma

EclEmma的介绍、安装与使用

北城以北 提交于 2020-11-18 23:59:18
1. EclEmma的介绍 EclEmma是一个开源的软件测试工具,可以在编码过程中查看代码调用情况、也可以检测单覆盖率。 2. Eclipse下EclEmma安装 1. 选择Help->Eclipse Marketplace->搜索EclEmma,Install; 2. 重启eclipse发现工具栏上出现Coverage图标,说明安装成功; 3. EclEmma使用 3.1 EclEmma查看代码调用情况 1. 新建一个项目,然后添加一个类,然后简单书写一些代码; 2. 右键项目->选择Coverage As->Java Application,可以得到如下结果: 3. 从运行结果可以看到,有多种颜色,其中 绿色表示代码被执行到 黄色表示代码部分执行到 红色表示代码没有被执行到 3.2 EclEmma检测覆盖率 1. 选择Window->Show View->Other->Java->Coverage可以看到代码执行的覆盖率; 2. 其中可以看到每一个类中代码被执行的百分比,见2,也可以看到整个项目代码被执行的百分比,见1; 3. 其中检测覆盖率可以用到单元测试中,查看单元测试覆盖率。 来源: oschina 链接: https://my.oschina.net/u/4258768/blog/3537477

Maven整合JaCoCo和Sonar,看看你的测试写够了没

假如想象 提交于 2020-07-25 13:25:37
1 简介 单元测试是保证代码质量的重要一环,而如何衡量单元测试写得好不好呢? 覆盖率(Coverage) 是一个重要指标。而 JaCoCo 则是专门为 Java 提供的用于检测测试覆盖率的工具,英文全称为 Java Code Coverage 。 本文将讲解如何在 Maven 项目中整合 JaCoCo ,并在 SonarQube 中展示。 SonarQube 的安装可以参考这篇文章: 《 Docker搭建代码检测平台SonarQube并检测maven项目 》 2 基本概念 这里所讲的 覆盖率 是指测试代码的覆盖率,这个指标有多种计算方式,如下是比较常用的有: 行覆盖率:执行代码行数 / 总代码行数,判断有多少行代码被测试执行; 类覆盖率:执行的类 / 代码中类总个数; 分支覆盖率:执行的逻辑分支数 / 总的分支数,一般用于检测是不是 lf/else 都有测试覆盖; 方法覆盖率:执行的方法数 / 代码总方法数,检测是否有方法被遗漏,构造方法也看作为方法。 圈复杂度:用于判断代码结构的复杂程序, JaCoCo 不考虑异常处理的分支;一般认为圈复杂度大于10,就存在比较大的风险,严格要求不可大于15。 颜色标识: JaCoCo 会通过颜色来标识代码覆盖情况,使其一目了然。红色表示没有覆盖,绿色表示已经覆盖,黄色表示部分覆盖。 执行方式: 执行 JaCoCo 有多种方式: (1

How does assert groupType != null contain 4 branches

吃可爱长大的小学妹 提交于 2020-06-28 03:16:09
问题 I need to test the following code. public List<PatientGroup> findGroups(final String groupType) throws HwBaseAppException { assert groupType != null;//4 branches here CriteriaBuilder criteriaBuilder=persistence.getCriteriaBuilder(); CriteriaQuery<PatientGroup> query = criteriaBuilder.createQuery(PatientGroup.class); Root<PatientGroup> patientGroupRoot = query.from(PatientGroup.class); Predicate condition=criteriaBuilder.equal(patientGroupRoot.get(PatientGroup_.active), Boolean.TRUE); Join

EclEmma, Java8 and Lambda - no coverage on lambda expression

江枫思渺然 提交于 2020-01-21 14:40:23
问题 I have a Java project under Eclipse Luna, with EclEmma 2.3.1.201405111647 (latest), which use Jacoco 0.7.1, which have support for Java 8 as stated in their changelog: "Version 2.3.1 (2014/05/11) Fixed ASM 5.0.1 dependency conflicts with new ASM bundles in Eclipse 4.4 (GitHub #83). Upgrade to JaCoCo 0.7.1 for full Java 8 support. I now have the following toString: @Override public String toString() { // [BLOCK0] if (0 == value) { return "0B"; } // [BLOCK1] final MutableLong val = new

Android Coverage launch with JaCoCo

半世苍凉 提交于 2020-01-11 12:37:52
问题 We have an Android application that we are building with Gradle/Android Studio and are using JaCoCo to generate code coverage reports for our unit tests; this is working great. We are also interested in being able to generate coverage reports for manual tests as well; that is, show what code was covered in an arbitrary application launch. It appears that JaCoCo's predecessor EclEmma was capable of this, but I have not been able to find any confirmation one way or the other about JaCoCo

How to exclude code (packages) in jococo, eclemma

会有一股神秘感。 提交于 2020-01-06 06:44:49
问题 I am trying to exclude code in jococo. I have given for the package that I want to exclude and vice versa tags in my code for the package that I want to include. but still ECLEMMA while junit coverage is reading whole code i.e. all packages and hence my code coverage goes down. Here is my code: <includes> <include>com.cfgh.controller.*</include> <include>com.cfgh.service.*</include> <include>com.cfgh.repository.*</include> </includes> <excludes> <exclude>com.cfgh.config.*</exclude> <exclude

How to exclude code (packages) in jococo, eclemma

蹲街弑〆低调 提交于 2020-01-06 06:44:04
问题 I am trying to exclude code in jococo. I have given for the package that I want to exclude and vice versa tags in my code for the package that I want to include. but still ECLEMMA while junit coverage is reading whole code i.e. all packages and hence my code coverage goes down. Here is my code: <includes> <include>com.cfgh.controller.*</include> <include>com.cfgh.service.*</include> <include>com.cfgh.repository.*</include> </includes> <excludes> <exclude>com.cfgh.config.*</exclude> <exclude

Code Coverage on Java Remote VM

旧巷老猫 提交于 2019-12-25 05:05:49
问题 How can I get (if it is even possible) the code coverage report running on a remote JAVA VM in Eclipse So I have a Unit test Suite running over the clients (for simplicity VM1) of the service layer (VM2). (The project was already setup this way and it is too deep in to re-architect that part) Debug works if i add a port listener as follows: <jvmFlag>-Xdebug</jvmFlag> <jvmFlag>-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y</jvmFlag> So was hoping to do something similar for a

Error while loading coverage session (code 5001)

旧城冷巷雨未停 提交于 2019-12-22 08:33:51
问题 I got the following error when I am trying to check coverage using EclEmma, please help me out: Error while loading coverage session (code 5001). Error while analyzing package fragment root java at F/solo-repository/target/test-classes (code 5007). File not found: D:\RDM Services\solo-repository\target\test-classes\com\charter\solo\account\repository\AccountBillInformationRepositoryTest.class. D:\RDM Services\solo-repository\target\test-classes\com\charter\solo\account\repository