1.eclipse新建java工程,添加junit库,新建junit test case51Testing软件测试网9_I"]"S m,FB%a
@Test
:dd@o)C S h'Y0 publicvoidtest() {51Testing软件测试网}cC/|8I5G*l
System.out.println("ant test");51Testing软件测试网~
dQ!c4wYo!_
}
%eA?
F;jM%_u9?02.工程下新建lib文件夹,将junit相关的两个jar包复制进来,并在window-prefence-ant-runtime-global
entires,添加jar包,把该两个包添加进去51Testing软件测试网A5BQs-t0I7]
junit.jar
Q4JB7_4Z!fM0org.hamcrest.core_1.3.0.v201303031735.jar 51Testing软件测试网4y vru0x-N.]L
3.新建build.xml文件如下,用来执行junit测试
zcQTeBs0<?xml
version="1.0" encoding="UTF-8"?>
-D6m'}7FV3O7F0 <projectname="javacTest"default="Junittest">
s'G4w%uJ%g!m&P_0 <propertyname="classes" value="build/classes"/>
"V"b%dpqx5y:lM9H0 <propertyname="lib"value="./lib"/>
Y;uG1FA^0 <!--输出报告的路径,jenkins从该路径取xml格式的报告结果-->51Testing软件测试网pu'T6rmOc
<property
name="junit_report" value="D:/jenkins/workspace/antt" /> 51Testing软件测试网 k a,p Q&Ild5Af0R
<targetname="clean"> 51Testing软件测试网XWKbcQ~
<deletedir="${classes}"/>
(L,~n5i4L'T s0 </target>
b;`@-_0W&V0 <targetname="complie"depends="clean"> 51Testing软件测试网aY8R6E0]
<mkdirdir="${classes}"/>
.RW.R `W0 <javacsrcdir="src"destdir="${classes}">
yU]hO+r_&w1L;{0 </javac>
rt8|1f;K
mR0 </target>
g9U7v(lT)U-\
N8s6L0
dC)Y!H W0 <targetname="Junittest"depends="complie">
v5M0ij%]%W^0 <junit fork="yes"printsummary="yes"showoutput="true">51Testing软件测试网@7OR)y-Hu;_+R5M
<!--生成xml报告,供jekins使用-->51Testing软件测试网5\#J4e-|k"XM]
<formatter type="xml"/>
#m
q_8RA/DW0 <testname="Test2" outfile="result"todir="${junit_report}"/>
j-LyTM0 <classpath>
.M/O#~ej5G0 <pathelementpath="${classes}"/>51Testing软件测试网{i/Z;c9I_
c7i9B
<filesetdir="${lib}">
Q$uo T#X"w0
<includename="**/*.jar"/>51Testing软件测试网"|G|U
~ ^GU3@8c
</fileset>51Testing软件测试网b@-S0H7f3d
</classpath>51Testing软件测试网
VF
Kv8ll8}&lU'd-Ve
</junit>51Testing软件测试网1\1l!B"b-V7IE Ta
</target>51Testing软件测试网S)e8J']%^a ~z4w
</project>51Testing软件测试网?;Igr-rgllFp
4.进入jenkins,新建job,选择增加构建步骤,选择invoke ant,build file输入该build.Xml文件的路径51Testing软件测试网&W!U6o"I'~J
5.增加构建后操作步骤,选择“publish junittest
result report“,测试报告栏输入:*.xml,jenkins将会从该job的workspace(如:D:\jenkins\workspace\anttest)去查找xml格式的junit报告
;\u-wO4p0bK|sC06.保存后,构建结果如下:51Testing软件测试网X%Tc
E oC@B!BL
51Testing软件测试网9B{+xG/DU c|G
.Jpx CG0diq0