在我当前的项目中,我正在使用 junit 测试。在我的本地电脑上运行我的 ant 文件会按预期生成我的测试报告,但是当竹子尝试运行我的测试时,它会产生以下输出。
我的错误是什么?
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
构建.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 输出: