gpt4 book ai didi

Ant 和雅 cocoa : Need to set junit's fork to "true" but not property that's true

转载 作者:行者123 更新时间:2023-12-04 20:50:01 25 4
gpt4 key购买 nike

我正在使用 Jacoco Junit 任务并尝试了以下操作:

    <!-- run the junit tests -->
<echo>DEBUG: $${junit.fork} = "${junit.fork}"</echo>
<jacoco:coverage
destfile="${target.dir}/jacoco.exec"
append="false">
<junit fork="${junit.fork}" includeAntRuntime="true">
<classpath>
<pathelement path="${main.destdir}"/>
<pathelement path="${test.destdir}"/>
</classpath>
<classpath refid="test.classpath"/>
<formatter type="${junit.formatter.type}"/>
<batchtest todir="${junit.batchtest.todir}">
<fileset dir="${test.destdir}" />
</batchtest>
</junit>
</jacoco:coverage>

并得到以下内容:
test:
[echo] DEBUG: ${junit.fork} = "true"
[jacoco:coverage] Enhancing junit with coverage

BUILD FAILED
D:\build.xml:233: Coverage can only be applied on a forked VM

Total time: 6 seconds

D:\>

如您所见, ${junit.fork}属性设置为 true ,我在 <junit fork="${junit.fork}"/> 中使用了该属性.

但是,我没有使用该属性,而是简单地设置了 <junit fork="true"> ,它工作正常:

    <jacoco:coverage
destfile="${target.dir}/jacoco.exec"
append="false">
<junit fork="true" includeAntRuntime="true">
<classpath>
<pathelement path="${main.destdir}"/>
<pathelement path="${test.destdir}"/>
</classpath>
<classpath refid="test.classpath"/>
<formatter type="${junit.formatter.type}"/>
<batchtest todir="${junit.batchtest.todir}">
<fileset dir="${test.destdir}" />
</batchtest>
</junit>
</jacoco:coverage>

我跑了 ant -d test当我使用 ${junit.fork} 时验证 Java JVM 是否正在 fork 属性(property)。

为什么 JaCoCo 坚持不 fork JUnit 测试,除非我设置了 fork字符串的参数 true而不是等于 true 的属性?

最佳答案

根据Jacoco coverage task source code :

...
public void enhanceTask(final Task task) {
final RuntimeConfigurable configurableWrapper = task.getRuntimeConfigurableWrapper();

final String forkValue = (String) configurableWrapper.getAttributeMap().get("fork");
if (!Project.toBoolean(forkValue)) {
throw new BuildException("Coverage can only be applied on a forked VM", getLocation());
}
addJvmArgs(task);
}
...

forkValue 是从 configureWrapper 中读取的。使用方法 ${junit.fork} 评估属性映射值(如 RuntimeConfigurable.maybeConfigure )由 Task.mayBeConfigure 调用.当您继续查看 Jacoco 源代码时:
...
public void addTask(final Task task) {
if (childTask != null) {
throw new BuildException("Only one child task can be supplied to the coverge task", getLocation());
}
this.childTask = task;
final String subTaskTypeName = task.getTaskType();
final TaskEnhancer enhancer = findEnhancerForTask(subTaskTypeName);
if (enhancer == null) {
throw new BuildException(format("%s is not a valid child of the coverage task", subTaskTypeName), getLocation());
}
if (isEnabled()) {
log(format("Enhancing %s with coverage", childTask.getTaskName()));
enhancer.enhanceTask(task);
}
task.maybeConfigure();
}
...

在增强任务 ( mayBeConfigure ) 后调用此方法 ( enhancer.enhanceTask(task); )。
我想这是您的问题和错误……我们应该将其报告给 jacoco 错误跟踪器。

Jacoco issue

关于 Ant 和雅 cocoa : Need to set junit's fork to "true" but not property that's true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12043041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com