51,412
社区成员
发帖
与我相关
我的任务
分享
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");
}
}
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);
}
}
<?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
