运行JUnit任务时,竹Ant任务失败 [英] Bamboo Ant Task fails when running junit task

查看:344
本文介绍了运行JUnit任务时,竹Ant任务失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的项目我使用JUnit测试。乳宁在我的本地PC我的Ant文件生成我的测试报告符合市场预期,但是当竹尝试运行我的测试中,它产生以下输出。

In my current project I'm using junit tests. Runing my ant file on my local pc produces my Test Report as expected, but when bamboo tries to run my tests, it produces the following output.

请告诉我我的错误?

SimplerTest.java

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

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>

蚂蚁-v输出:

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

推荐答案

感谢您的详细的Ant的输出。

Thanks for the verbose Ant output.

您似乎在你的竹服务器上运行Ant的1.9.0。有一个已知的问题(缺陷 54835 - 类路径的使用似乎在JUnit Ant任务被打破?)在Ant bug跟踪系统,这是对SO开始由一个类似问题的海报:<一个href=\"http://stackoverflow.com/questions/15979391/class-not-found-with-ant-ivy-and-junit-error-in-build-xml\">Class未发现有蚂蚁,常春藤和JUnit - 错误的build.xml :

It appears you are running Ant 1.9.0 on your Bamboo server. There is a known issue (bug 54835 - Classpath use seems to be broken in junit ant task?) in the Ant bug tracker, which was started by the poster of a similar question on SO: "Class not found with Ant, Ivy and JUnit - error in 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)
...

这个问题并没有一个明确的/简短的回答,但错误报告所做的:

That question didn't have a clear / short answer, but the bug report does:

它看起来像类搜索被委托给系统的
  类加载器,而不是由蚂蚁类加载器所处理(在
  系统类加载器没有的JUnit knoweldge因为JUnit是不上
  芯蚂蚁类路径,但由常春藤加到JUnit的任务)。鉴于一些
  JUnit类必须已加载到已达到这个
  点,蚂蚁类加载器可以看到常春藤加载JUnit的广口瓶,但
  拆分类加载器似乎在尝试时要正确下放
  加载了JUnit运行的类。

It looks like the class search is being delegated to the System's classloader rather than being handled by the Ant Classloader (the system Classloader has no knoweldge of JUnit since JUnit isn't on the core Ant Classpath, but is added to the JUnit task by Ivy). Given some JUnit classes must have already been loaded to have reached this point, the Ant Classloader can see the JUnit jars loaded by Ivy, but the Split Classloader seems to be delegating incorrectly when trying to load classes used by the JUnit Runner.

在换句话说:Ant的junit任务有缺陷,也不会工作,我觉得你这个具体问题的影响。错误报告的推移并列出这些修复/解决方法:

In other words: Ant's JUnit task has bugs and won't work, and I think you are affected by this specific bug. The bug report goes on and lists these fixes / workarounds:


  • 等待蚂蚁1.9.1(错误报告被标记为固定和释放,可以预计很快)

  • 您的JUnit JAR复制到的antlib 目录,并继续使用蚂蚁1.9.0。这不,如果你想混的JUnit版本的那么好,但如果你用的是4.10左右,它应该工作。

  • 使用蚂蚁1.8.4

  • Wait for Ant 1.9.1 (the bug report is marked as fixed and the release can be expected very soon)
  • Copy your JUnit JAR into your ANTLIB directory and keep using Ant 1.9.0. This is not so good if you want to mix JUnit versions, but it should work if all you use is 4.10 or so.
  • Use Ant 1.8.4

这篇关于运行JUnit任务时,竹Ant任务失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆