首页 新闻 会员 周边

Ant+junit单元测试

0
悬赏园豆:50 [待解决问题]

我自己写的小demo可以运行,开发环境是没网的 报错图上,跪求大佬指点

代码贴下面

<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-junit-demo" default="junit" basedir=".">
<!-- =================================================================== -->
<!-- 变量设置 -->
<!-- =================================================================== -->
<!-- 源代码src路径 -->
<property name="src.path" value="src/main/java" />
<!-- 单元测试代码路径 -->
<property name="test.path" value="src/test/java" />
<!-- 编译文件class路径 -->
<property name="build.path" value="build" />
<!-- jar包路径 -->
<property name="dist.path" value="dist" />
<!-- lib包路径 -->
<property name="lib.path" value="lib" />
<!-- 生成报告junit4.xml路径 -->
<property name="report.path" value="report" />

<!-- =================================================================== -->
<!-- 设置classpath  绝对路径 dir="E:\Project\ant\lib"-->
<!-- =================================================================== -->
<path id="compile.path">
	<fileset dir="${lib.path}">
		<include name="/*.jar" />
	</fileset>

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

<!-- 初始化 -->
<target name="init">
	<mkdir dir="${build.path}" />
	<mkdir dir="${report.path}" />
</target>

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

<!-- =================================================================== -->
<!-- 编译测试文件,初始化目录 -->
<!-- =================================================================== -->
<target name="compile" depends="init">
	<javac srcdir="${src.path}" destdir="${build.path}"  includeantruntime="true" >
		<classpath refid= "compile.path"/>
	</javac>
	<javac srcdir="${test.path}" destdir="${build.path}" classpathref="compile.path" includeantruntime="true" />
</target>

<!-- =================================================================== -->
<!-- 执行测试案例 -->
<!-- =================================================================== -->
<target name="junit" depends="compile">
	<junit printsummary="true" fork="true">
		<formatter type="xml" usefile="true" />

		<classpath refid="compile.path" />

		<batchtest fork="on" todir="${report.path}" haltonfailure="no">
			<fileset dir="${build.path}">
				<include name="**/*Test.class" />
			</fileset>
		</batchtest>
	</junit>
</target>

<target name="junit-report" depends="junit">
	<!-- 产生单元测试报表文档 -->
	<junitreport todir="${report.path}">
		<fileset dir="${report.path}">
			<include name="TEST-*.xml" />
		</fileset>

		<report format="frames" todir="${report.path}/html"/>
	</junitreport>
</target>

<target name="make-jar" depends="compile" description="make jar file">
	<jar jarfile="${dist.path}/ant-junit-demo.jar">
		<fileset dir="${build.path}">
			<!--除去test文件-->
			<exclude name="**/*Test.class" />
		</fileset>
	</jar>
</target>

</project>

打工人的主页 打工人 | 初学一级 | 园豆:152
提问于:2020-11-04 17:32
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册