如何忽略使用 EclEmma 和 Eclipse 扫描某些类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14448603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:50:32  来源:igfitidea点击:

How do I ignore scanning certain classes using EclEmma and Eclipse?

javaeclipseeclemma

提问by sdasdadas

I am using EclEmma (inside of Eclipse) to scan my JUnit code coverage. This works correctly - however, I do not want EclEmma to scan my src/viewfolder since it contains Swing code that I consider not worthy of testing.

我正在使用 EclEmma(在 Eclipse 内部)来扫描我的 JUnit 代码覆盖率。这工作正常 - 但是,我不希望 EclEmma 扫描我的src/view文件夹,因为它包含我认为不值得测试的 Swing 代码。

Is there any way to ignore this folder when EclEmma runs so that it: a) runs faster, and b) does not skew the coverage percentage?

当 EclEmma 运行时,有什么方法可以忽略此文件夹,以便:a) 运行得更快,并且 b) 不会使覆盖率发生偏差?

EDIT:

编辑:

My project's structure is:

我的项目结构是:

src/view
src/model
src/controller

I have tried these (possibly others) with the Path Entries section in the Preferences page:

我已经在首选项页面中的路径条目部分尝试了这些(可能是其他的):

"src/view"
"src/view/*"
"view"
"view/*"
src/view

These are using the Excludes section in the Preferences page:

这些正在使用“首选项”页面中的“排除”部分:

*
*View*
*View*.class
src/view/*View*
src/view/*View*.class

They all leave me with the same result of it analysing my entire src folder.

他们都给我留下了相同的结果,因为它分析了我的整个 src 文件夹。

采纳答案by stevebot

You can specify an exclude field:

您可以指定排除字段

Excludes: A list of class names that should be excluded from execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?). (Default: empty)

排除:应从执行分析中排除的类名列表。列表条目由冒号 (:) 分隔,并且可以使用通配符(* 和 ?)。(默认:空)

However, it might be easier to use their options for classpath matching:

但是,使用它们的选项进行类路径匹配可能更容易:

Only path entries matching: Comma separated list of strings that must match with the class path entry. A class path entry matches the filter, if it contains one of the given strings. (e.g. "src/main/java", Default: no filter)

仅匹配路径条目:必须与类路径条目匹配的以逗号分隔的字符串列表。类路径条目与过滤器匹配,如果它包含给定的字符串之一。(例如“src/main/java”,默认值:无过滤器)

See eclemma - how to ignore sourceabout how to ignore src folders.

请参阅eclemma - 如何忽略有关如何忽略 src 文件夹的源代码

Also please note their caution,

也请注意他们的谨慎,

Warning: If your settings do not match any of the class path entries in your project(s), every new launch in coverage mode will have an empty analysis scope.

警告:如果您的设置与项目中的任何类路径条目都不匹配,则覆盖模式下的每个新启动都将有一个空的分析范围。

回答by newfivefour

[Edit] The maintainers says you cannot, except one the source directory level: https://github.com/jacoco/eclemma/issues/70

[编辑] 维护者说你不能,除了源目录级别:https: //github.com/jacoco/eclemma/issues/70

I thought eclemma wasn't excluding files: it is. Just not as I thought.

我认为 eclemma 不排除文件:它是。只是不像我想的那样。

When you go into excludes in preferences and specify your.classes.here.*, for example, that means those classes won't count towards your getting all your code covered, not that those classes won't be included in what needs to be covered by tests.

例如,当您进入首选项中的排除并指定 your.classes.here.* 时,这意味着这些类不会计入您获得所有代码的覆盖范围,而不是这些类不会包含在需要的内容中被测试覆盖。

Try it and see. Try to exclude a class you know have coverage in it. Once you put that to the excludes preference, on a new coverage run they'll still be there in the coverage window, but they'll come up as 0% and will all be in red.

试试看。尝试排除您知道其中有覆盖范围的类。一旦您将其设置为排除首选项,在新的覆盖率运行中,它们仍将出现在覆盖率窗口中,但它们将显示为 0% 并且全部显示为红色。

Rather useless if you ask me. I'm still searching for an adequate solution to exclude classes by name from the classes that need to be covered by tests.

如果你问我,那就没用了。我仍在寻找适当的解决方案,以便从需要测试覆盖的类中按名称排除类。

回答by Stoat

I have given up on EclEmma because I can't get it to do the things I want it to do, so I use a different method - I'll document it here in case it helps anyone else.

我已经放弃了 EclEmma,因为我无法让它做我想让它做的事情,所以我使用了不同的方法 - 我会在这里记录它,以防它对其他人有帮助。

  1. To exclude classes from test, I name all my test classes as *Case.java and then include or exclude them via SuiteClasses. You can read more about that at https://github.com/junit-team/junit4/wiki/Aggregating-tests-in-suites
  2. To measure coverage, I use Maven and Cobertura. This will test just the files specified in my test suites and produce coverage reports accordingly.
  1. 为了从测试中排除类,我将所有测试类命名为 *Case.java,然后通过 SuiteClasses 包含或排除它们。您可以在https://github.com/junit-team/junit4/wiki/Aggregating-tests-in-suites阅读更多相关信息
  2. 为了测量覆盖率,我使用了 Maven 和 Cobertura。这将仅测试我的测试套件中指定的文件并相应地生成覆盖率报告。