jenkins+ant执行junit测试

上一篇 / 下一篇  2015-08-22 20:07:39 / 个人分类:持续集成

    1.eclipse新建java工程,添加junit库,新建junit test case51Testing软件测试网0aZ.Q,J$b4jy.S

      @Test51Testing软件测试网2f jRca?s3`{(c

   publicvoidtest() {

X:S~2S&{Ck'C0

        System.out.println("ant test");

C"CK`)Z#p}A v/E~+B0

            }51Testing软件测试网,e|'J#_"V6P7^1m

2.工程下新建lib文件夹,将junit相关的两个jar包复制进来,并在window-prefence-ant-runtime-global entires,添加jar包,把该两个包添加进去

qU1s!bw'Yi/F0

   junit.jar

$L8Y"p5kt;u|j0

org.hamcrest.core_1.3.0.v201303031735.jar 

-lR(r.a1?$u8Ed0

3.新建build.xml文件如下,用来执行junit测试51Testing软件测试网[kh#X'u]1b

<?xml version="1.0" encoding="UTF-8"?>

f3p3C)^*[U(G7@y6q0

   <projectname="javacTest"default="Junittest">51Testing软件测试网#G/r2n/m:K} JH

         <propertyname="classes" value="build/classes"/>51Testing软件测试网;L c%l#h8j-nL

         <propertyname="lib"value="./lib"/>  

}Hon:]A0

          <!--输出报告的路径,jenkins从该路径取xml格式的报告结果-->51Testing软件测试网:}P!~2Wdz*P-@v pY

        <property name="junit_report" value="D:/jenkins/workspace/antt" /> 51Testing软件测试网[t0`1N|(Pyc

        <targetname="clean">     51Testing软件测试网 jHE$C-?j t3SB

             <deletedir="${classes}"/>

i"y j$}#s0

         </target>

(g XXO-a;O S3Z0

         <targetname="complie"depends="clean">      

E!@N[A,j.I0

             <mkdirdir="${classes}"/>

-wy,E ok*M0

              <javacsrcdir="src"destdir="${classes}"> 

A `K8l"c4P;yM!w0

              </javac>51Testing软件测试网*N%H(Xq@

         </target>

J#Z-v'|@4wa_s6O0

 51Testing软件测试网(S)f8YxiY!x

        <targetname="Junittest"depends="complie">51Testing软件测试网 W~_D8_&B*tB

            <junit fork="yes"printsummary="yes"showoutput="true">51Testing软件测试网iLs~.t1\9O%{

               <!--生成xml报告,供jekins使用-->51Testing软件测试网$y'ad~zV7D

              <formatter type="xml"/>

Z7u3U+f3Py0

             <testname="Test2" outfile="result"todir="${junit_report}"/> 51Testing软件测试网 ?_ ~ x,ezy

               <classpath>

'z&E-t1~V0

                  <pathelementpath="${classes}"/>

ADRUVG+^&X+ur R0

                  <filesetdir="${lib}">51Testing软件测试网TMr O9o${!|p Ya

                       <includename="**/*.jar"/>

/BD5gC#n)i0

                  </fileset>

){,Lu w nO+\&no5s0

              </classpath>

/_,L$Z3NE5q0

          </junit>

x:F5m5\ r_jf0

       </target>

LlI.S4V1o"A0

   </project>51Testing软件测试网*\~5i0C5I!jm$Z

4.进入jenkins,新建job,选择增加构建步骤,选择invoke antbuild file输入该build.Xml文件的路径51Testing软件测试网D+f%yu's-kJ)j

5.增加构建后操作步骤,选择“publish junittest result report“,测试报告栏输入:*.xml,jenkins将会从该jobworkspace(如:D:\jenkins\workspace\anttest)去查找xml格式的junit报告51Testing软件测试网xq;A+pR g;a%f*v6a

6.保存后,构建结果如下:51Testing软件测试网Wc3g n.Bw+t0p

*VN!zSB.D&a%|0

51Testing软件测试网\BnpHd3I!Fh


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar