ant跑junit一直失败

fanweiyang1 2017-10-16 10:59:35
eclipse上做了一个简单的junit的demo,在eclipse中run junit成功 但是用ant脚本的时候一直报错
目录结构:

SourceTest.java:

public class SourceTest {

/**
* @param args
*/
public void SourceTest() {
System.out.println("init...");
}
public static void main(String[] args) {
System.out.println("main");
}

public int Add(int op1 ,int op2)
{
System.out.println("source");
return op1+op2;
}
public void test1()
{
System.out.println("121312");
}
}


AntTest.java

public class AntTest {

SourceTest test1 = new SourceTest() ;
@Test
public void testa() {

// System.out.println(test1.Add(1, 2));
System.out.println("test");
int c =test1.Add(1, 2);
assertEquals(3, c);
}
@Test
public void testb() {

// System.out.println(test1.Add(1, 2));
System.out.println("test");
int c =test1.Add(1, 2);
assertEquals(4, c);
}

}

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="AntDemo" default="junit" basedir=".">
<!-- =================================================================== -->
<!-- 变量设置 -->
<!-- =================================================================== -->

<!-- 源代码src路径 -->
<property name="src.path" value="src/source"/>
<!-- 编译文件class路径 -->
<property name="build.path" value="build"/>
<!-- 单元测试代码路径 -->
<property name="test.path" value="src/test"/>
<!-- lib包路径 -->
<property name="lib.path" value="lib"/>

<!-- =================================================================== -->
<!-- 设置classpath -->
<!-- =================================================================== -->
<path id="compile.path">
<fileset dir="${lib.path}">
<include name="**/*.jar"/>

</fileset>
<pathelement path="${build.path}"/>
</path >

<!-- =================================================================== -->
<!-- 清除历史编译class -->
<!-- =================================================================== -->
<target name="clean" description="clean">
<delete dir="${build.path}"/>
</target>

<!-- =================================================================== -->
<!-- 编译测试文件,初始化目录 -->
<!-- =================================================================== -->
<target name="compile" description="compile">
<mkdir dir="${build.path}"/>
<javac srcdir="${src.path}" destdir="${build.path}" classpathref="compile.path" includeantruntime="on"/>
<javac srcdir="${test.path}" destdir="${build.path}" classpathref="compile.path" includeantruntime="on"/>
</target>

<!-- =================================================================== -->
<!-- 执行测试案例 -->
<!-- =================================================================== -->
<target name="junit" depends="clean,compile">
<junit printsummary="withOutAndErr" showoutput="yes">
<classpath refid="compile.path"/>
<test name="AntTest"/>
</junit>
</target>
<echo message = "compile.path"/>
</project>


报错信息

Buildfile: D:\workspace\eclipse_space\test123\build.xml
[echo] compile.path
clean:
[delete] Deleting directory D:\workspace\eclipse_space\test123\build
compile:
[mkdir] Created dir: D:\workspace\eclipse_space\test123\build
[javac] Compiling 1 source file to D:\workspace\eclipse_space\test123\build
[javac] Compiling 1 source file to D:\workspace\eclipse_space\test123\build
junit:
[junit] Running AntTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test AntTest FAILED
BUILD SUCCESSFUL
Total time: 831 milliseconds

...全文
154 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanweiyang1 2017-10-18
  • 打赏
  • 举报
回复
没人支援么
fanweiyang1 2017-10-16
  • 打赏
  • 举报
回复
google了一下找到了几个相同的问题 但都没有解决方案 就这么点分可用了 求指点迷津

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧