繁体   English   中英

运行junit任务时,Bamboo Ant任务失败

[英]Bamboo Ant Task fails when running junit task

在我目前的项目中,我正在使用junit测试。 在我的本地电脑上运行我的蚂蚁文件按预期生成我的测试报告,但是当竹子试图运行我的测试时,它会产生以下输出。

我的错是什么?

SimplerTest.java

import static org.junit.Assert.*;

import org.junit.Test;

public class SimplerTest {


@Test
public void dummerTest()
{
    assertTrue(true);
}
}

本地输出:

Buildfile: C:\Users\jussi\git\kingdom-builder-repository\build.xml

compile-test:
[javac] Compiling 1 source file to C:\Users\jussi\git\kingdom-builder-repository\bin

junit:
    [junit] Running me.jussi.kingdombuilder.SimplerTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0,062 sec

main:

BUILD SUCCESSFUL
Total time: 1 second

服务器输出:

compile-test:
[javac] Compiling 1 source file to /var/atlassian/application-data/bamboo/xml-data/build-dir/KB-KBP1-JOB1/bin

junit:

BUILD FAILED
/var/atlassian/application-data/bamboo/xml-data/build-dir/KB-KBP1-JOB1/build.xml:108: Using loader AntClassLoader[/opt/apache-ant-1.9.0/lib/ant-launcher.jar:/opt/ant/lib/ant.jar:/opt/ant/lib/ant-junit.jar:/opt/ant/lib/ant-junit4.jar:/var/atlassian/application-data/bamboo/xml-data/build-dir/KB-KBP1-JOB1/kingdom-builder/libs/junit-4.10.jar:/var/atlassian/application-data/bamboo/xml-data/build-dir/KB-KBP1-JOB1/bin] 
on class org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter: java.lang.NoClassDefFoundError: junit/framework/TestListener

build.xml文件

<?xml version="1.0"?>
<project name="KingdomBuild" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->

<property name="test.src.dir" location="kingdom-builder/test" />
<property name="build.dir" location="bin" />
<property name="test.report.dir" location="testreport" />

<!-- Define the classpath which includes the junit.jar and the classes after compiling-->
<path id="junit.class.path">
    <pathelement location="kingdom-builder/libs/junit-4.10.jar" />
    <pathelement location="${build.dir}" />
</path>

<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile-test">
    <javac srcdir="${test.src.dir}" destdir="${build.dir}" includeantruntime="false">
        <classpath refid="junit.class.path" />
    </javac>
</target>


<!-- Run the JUnit Tests -->
<!-- Output is XML, could also be plain-->
<target name="junit" depends="compile-test">
    <junit printsummary="on" fork="true" haltonfailure="true">
        <classpath refid="junit.class.path" />
        <formatter type="xml" />
        <batchtest todir="${test.report.dir}">
            <fileset dir="${build.dir}">
                <include name="**/*Test*.class" />
            </fileset>
        </batchtest>
    </junit>
</target>

<target name="main" depends="junit">
    <description>Main target</description>
</target>
</project>

ant -v输出:

http://nopaste.info/1abdd27a8e.html

感谢详细的Ant输出。

您的Bamboo服务器上似乎正在运行Ant 1.9.0。 在Ant bug跟踪器中有一个已知的问题(bug 路由器中的 bug 54835 - 类路径使用似乎被破坏了吗? ),这是由关于SO的类似问题的海报开始的:“ Ant,Ivy和JUnit找不到类- build.xml中的错误? “:

BUILD FAILED
/home/andrew/project/guice/hg/build.xml:33: java.lang.NoClassDefFoundError: junit/framework/TestListener
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
...
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
...

这个问题没有明确/简短的答案,但错误报告确实:

看起来类搜索被委托给System的类加载器而不是由Ant类加载器处理(系统类加载器没有JUnit的知识,因为JUnit不在核心Ant类路径上,而是由Ivy添加到JUnit任务中)。 鉴于某些JUnit类必须已经加载到这一点,Ant类加载器可以看到Ivy加载的JUnit jar,但是当尝试加载JUnit Runner使用的类时,Split Classloader似乎被错误地委派。

换句话说:Ant的JUnit任务有bug并且不起作用,我认为你受到这个特定bug的影响。 错误报告继续并列出了这些修复/解决方法:

  • 等待Ant 1.9.1(错误报告被标记为已修复,可以很快发布该版本)
  • 将JUnit JAR复制到ANTLIB目录中并继续使用Ant 1.9.0。 如果你想混合JUnit版本,这不是很好,但如果你使用的只是4.10左右它应该可以工作。
  • 使用Ant 1.8.4

暂无
暂无

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

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