- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两段代码给我带来了麻烦。我用单元测试测试它们,使用 cobertura 来分析测试覆盖率,我不明白条件覆盖率是如何计算的。
这是第一篇:
if ((x.getInt() == a)
|| (x.getInt() == y.getInt()) { ...
if ((x == null)
|| ObjectUtils.equals(x.getInt(), a)
|| ObjectUtils.equals(x.getInt(), y.getInt())) {
...
how does cobertura handle conditional coverage in these cases, and why does that lead to 6 cases?
最佳答案
覆盖率不是通过测试 bool 标志状态的所有可能组合来衡量的,而是仅通过测试足以覆盖所有用例的那些组合来衡量。
考虑以下类:
public class MyClass {
public boolean allOr(boolean x, boolean y) {
return x || y;
}
public boolean allOr(boolean x, boolean y, boolean z) {
return x || y || z;
}
public boolean allOr(boolean w, boolean x, boolean y, boolean z) {
return w || x || y || z;
}
public boolean allAnd(boolean x, boolean y) {
return x && y;
}
public boolean allAnd(boolean x, boolean y, boolean z) {
return x && y && z;
}
public boolean andOr(boolean x, boolean y, boolean z) {
return x && y || z;
}
public boolean orAnd(boolean x, boolean y, boolean z) {
return (x || y) && z;
}
}
public class MyClassTest {
@Test
public void testAllOr2() {
MyClass instance = new MyClass();
// For OR clause, test that all false returns false
assertFalse(instance.allOr(false, false));
// For OR clause, test that any one true returns true
assertTrue(instance.allOr(false, true));
assertTrue(instance.allOr(true, false));
}
@Test
public void testAllOr3() {
MyClass instance = new MyClass();
// For OR clause, test that all false returns false
assertFalse(instance.allOr(false, false, false));
// For OR clause, test that any one true returns true
assertTrue(instance.allOr(false, false, true));
assertTrue(instance.allOr(false, true, false));
assertTrue(instance.allOr(true, false, false));
// These do not add to coverage
// assertTrue(instance.allOr(false, true, true));
// assertTrue(instance.allOr(true, false, true));
// assertTrue(instance.allOr(true, true, false));
// assertTrue(instance.allOr(true, true, true));
}
@Test
public void testAllOr4() {
MyClass instance = new MyClass();
// For OR clause, test that all false returns false
assertFalse(instance.allOr(false, false, false, false));
// For OR clause, test that any one true returns true
assertTrue(instance.allOr(false, false, false, true));
assertTrue(instance.allOr(false, false, true, false));
assertTrue(instance.allOr(false, true, false, false));
assertTrue(instance.allOr(true, false, false, false));
}
@Test
public void testAllAnd2() {
MyClass instance = new MyClass();
// For AND clause, test that all true returns true
assertTrue(instance.allAnd(true, true));
// For AND clause, test that any one false returns false
assertFalse(instance.allAnd(true, false));
assertFalse(instance.allAnd(false, true));
}
@Test
public void testAllAnd3() {
MyClass instance = new MyClass();
// For AND clause, test that all true returns true
assertTrue(instance.allAnd(true, true, true));
// For AND clause, test that any one false returns false
assertFalse(instance.allAnd(false, true, true));
assertFalse(instance.allAnd(true, false, true));
assertFalse(instance.allAnd(true, true, false));
}
@Test
public void testAndOr() {
MyClass instance = new MyClass();
// Since AND takes precedence,
// OR is the external operator, AND is the internal operator
// For the AND clause, false can be achieved in two ways
// Compare to testAllAnd2 # 2, 3
assertFalse(instance.andOr(true, false, false));
assertFalse(instance.andOr(false, true, false));
// This completes the first test case for the external operator
// Compare to testAllOr2 # 1
// Now irrespective of the arguments
// as long as the value returned by the internal operation is false
// we can perform the testAllOr2 # 2
assertTrue(instance.andOr(true, false, true));
// We do not need the case for false, true, true
// because we have tested that no matter what the first two args are
// it does not make a difference as long as one of them is false
// However, if both args are true
// the value returned by the internal operation is true
// we can perform the testAllOr2 # 3
// This is only possible in one way
// Compare testAllAnd2 # 1
assertTrue(instance.andOr(true, true, false));
}
@Test
public void testOrAnd() {
MyClass instance = new MyClass();
// Since OR takes precedence,
// AND is the external operator, OR is the internal operator
// For the OR clause, true can be achieved in two ways
// Compare to testAllOr2 # 2, 3
assertTrue(instance.orAnd(false, true, true));
assertTrue(instance.orAnd(true, false, true));
// This completes the first test case for the external operator
// Compare to testAllAnd2 # 1
// Now irrespective of the arguments
// as long as the value returned by the internal operation is true
// we can perform the testAllAnd2 # 2
assertFalse(instance.orAnd(false, true, false));
// We do not need the case for true, false, false
// because we have tested that no matter what the first two args are
// it does not make a difference as long as one of them is true
// However, if both args are false
// the value returned by the internal operation is false
// we can perform the testAllAnd2 # 3
// This is only possible in one way
// Compare testAllOr2 # 1
assertFalse(instance.orAnd(false, false, true));
}
}
关于code-coverage - Cobertura 中条件覆盖的计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14561679/
您好,我已经在互联网上进行了大量搜索,但是我找不到为我们的golang项目生成html coverage文件的简便方法,但至少我可以得到如下所示的coverage.dat文件 mode: set pa
我正在尝试为 cython 模块生成代码覆盖率报告,并面临问题。 我有一个简单的 C++ 代码:apple.h 和 苹果.cpp 文件。 cpp 文件很简单: using namespace std;
我正在开发一个包含一些测试用例的 module1。我有另一个模块2,它可以运行这些测试用例并生成覆盖范围。目前 .coverage 文件夹是在调用 module2 的当前工作目录中生成的。有没有办法指
我最近将代码覆盖引入了我的项目。它创建了一份我可以查看的报告,而且它似乎运行良好。 唯一的问题是它缺少我的测试——我现在没有很好的代码覆盖率,但它报告所有类和其他文件的覆盖率为 0%。 我可以看到正在
我正在尝试将我当前的 AngularJS 项目与 Karma Coverage 集成。请在下面找到 package.json 和我的 karma 配置 . Package.json { "name
我正在尝试为我的 gitlab 项目显示准确的覆盖率徽章。 问题是我有几个包,在 gitlab-ci.yml,我运行 go test $(go list ./... | grep -v /vendor
由于贡献线,Jenkins 仪表板上的“W”列显示了我所有 PHP 项目的 Storm Clover Coverage: Conditionals 0% (0/0) 因为 PHP_CodeCovera
我能够按照以下步骤获得代码覆盖率报告, 启用对所需构建类型的覆盖(例如调试) buildTypes { 调试{ testCoverageEnabled 真 } } 应用Jacoco插件并设置版本 应用
当 rcov 生成报告时,它会显示每个文件的“总覆盖率”和“代码覆盖率”。这两个指标有什么区别? 最佳答案 来自 http://www.rubydoc.info/github/relevance/rc
我正在尝试获取基于 arm 的嵌入式系统的代码覆盖率。使用 x86 进行交叉编译。基本上,我有一个交叉分析问题。 对于我想要生成代码覆盖率数据的应用程序,我定义了一个信号处理程序,我在其中调用 __g
与 cobertura-maven-plugin可以使用 ignoreTrivial 从代码覆盖率中排除 setter 和 getter选项。 jacoco-maven-plugin是否也有这种可能?
有没有人用 Jenkins CI 安装了 Grails -code-coverage 插件? 如果可以,请指导我完成设置? 最佳答案 您可以试试这个教程:code coverage 关于code-co
系统定义: 2012 macbook pro 运行 Sierra, Docker 版本:17.12.0-ce-mac49 (21995) 问题: 我在容器中使用“覆盖运行”运行我的 python 应用
尝试启动并运行代码覆盖率,我只是先阅读文档。我发现一些文章提到了使用 --coverage 标志进行构建,而其他文章提到了 --ftest-coverage。 两个描述似乎都说它们做同样的事情,但我不
尽管安装了插件,但我似乎无法使用 Nose 获得代码覆盖率。 关于如何解决这个问题的任何想法? 12:15:25 ~/sandbox/ec$ nosetests --plugins Plugin xu
我正在尝试在预先提交的钩子(Hook)中对暂存文件运行测试。到目前为止,一切都很好。可以使用 pre-commit和 lint-staged NPM 包。 来自 package.json 的片段: {
我有 .coverage 文件指示由 coverage.py 生成的我的 Django 项目的代码覆盖率: coverage run --branch --source='.' manage.py t
我试图让 Cobertura 在我的 ant 脚本中运行。一切顺利(源代码构建、junit 测试、cobertura 报告(xml/html);但在 html 报告中,代码覆盖率始终为 0% ...
因为团队内部开启了一个持续的前端代码质量改进计划,其中一个专项就是TS类型覆盖率,期间用到了 type-coverage 这个仓库,所以借这篇文章分享一下这个工具,并顺便从源码阅读的角度来
我通过在服务器启动脚本中将 -javaagent 设置为 jvm 选项来创建 jacoco.exec 文件。现在我想使用覆盖率执行文件生成覆盖率报告。 我已经了解了所有 Jacoco 报告生成选项(m
我是一名优秀的程序员,十分优秀!