1.eclipse新建java工程,添加junit库,新建junit test case51Testing软件测试网X9D]
xJ2f8f
@Test51Testing软件测试网}8tD5fsH c!R0A
publicvoidtest() {51Testing软件测试网l-`$_+BPg*kpU
System.out.println("ant test");
)V2AP1wk,r-A_ R0 }
;g`X8M8R1D02.工程下新建lib文件夹,将junit相关的两个jar包复制进来,并在window-prefence-ant-runtime-global
entires,添加jar包,把该两个包添加进去
d2W-?8tcC0 junit.jar
y8}KnT1i]0org.hamcrest.core_1.3.0.v201303031735.jar 51Testing软件测试网 UV4lR%B7Z"l%U
3.新建build.xml文件如下,用来执行junit测试
,ZpE z%UwP0<?xml
version="1.0" encoding="UTF-8"?>
q}1I!qk,A
z'La0 <projectname="javacTest"default="Junittest">
'vbI%bL
pp0 <propertyname="classes" value="build/classes"/>51Testing软件测试网6?ru6KfURv
<propertyname="lib"value="./lib"/> 51Testing软件测试网/uQ
M'R5MBs
<!--输出报告的路径,jenkins从该路径取xml格式的报告结果-->51Testing软件测试网"W:E%p!L ?2C8EB(?
<property
name="junit_report" value="D:/jenkins/workspace/antt" />
,j,^
n.EQ;n$v7[0 <targetname="clean"> 51Testing软件测试网
T J%CbsGqgW
<deletedir="${classes}"/>
!y'U8h!g/vV0 </target>51Testing软件测试网0{ZzYN*a?9^/w
<targetname="complie"depends="clean">
r \J8`1KH0 <mkdirdir="${classes}"/>
&M)Ks h:~!O0 <javacsrcdir="src"destdir="${classes}">
]GF+W+wT4@0 </javac>
G$CFYr`1y
Y0 </target>51Testing软件测试网;e].L
qUD|
Kz&?OI3l4b0 <targetname="Junittest"depends="complie">51Testing软件测试网\,h&Q2P&D
<junit fork="yes"printsummary="yes"showoutput="true">51Testing软件测试网2N$Cv5O5K+c&SBlE
<!--生成xml报告,供jekins使用-->
4W3S;B3q*I8I0 <formatter type="xml"/>
B+hU\#T0 <testname="Test2" outfile="result"todir="${junit_report}"/>
,_?9_#i$X
|.Cj ?U0 <classpath>51Testing软件测试网@ mF+z+w
tV$Ee
<pathelementpath="${classes}"/>51Testing软件测试网FA%N'e Z8r
<filesetdir="${lib}">
#C3n;J.jFsJ7{0VIG0
<includename="**/*.jar"/>
'Z T7|E\qn;f]0x8o0 </fileset>
'~kZ [A/f1W|;D0 </classpath>
n e$xfIo U0 </junit>
e/R]~5t2w&?`0 </target>51Testing软件测试网#HxA;i"fr/b.`
</project>
3wB M#E&c04.进入jenkins,新建job,选择增加构建步骤,选择invoke ant,build file输入该build.Xml文件的路径
1dm;o0h:J3rj05.增加构建后操作步骤,选择“publish junittest
result report“,测试报告栏输入:*.xml,jenkins将会从该job的workspace(如:D:\jenkins\workspace\anttest)去查找xml格式的junit报告
-~5IO"E7R06.保存后,构建结果如下:
gK$nY{r:O0
4]`c }2{g0n
k051Testing软件测试网&ReMK(_