jenkins+ant执行junit测试

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

    1.eclipse新建java工程,添加junit库,新建junit test case51Testing软件测试网9_I"]"Sm,FB%a

      @Test

:dd@o)C Sh'Y0

   publicvoidtest() {51Testing软件测试网}cC/|8I5G*l

        System.out.println("ant test");51Testing软件测试网~ d Q!c4wYo!_

            }

%eA? F;jM%_u9?0

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

   junit.jar

Q4JB7_4Z!fM0

org.hamcrest.core_1.3.0.v201303031735.jar 51Testing软件测试网4y vru0x-N.]L

3.新建build.xml文件如下,用来执行junit测试

zcQTeB s0

<?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:l M9H0

         <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!HW0

        <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/D W0

             <testname="Test2" outfile="result"todir="${junit_report}"/> 

j-LyTM0

               <classpath>

.M/O#~ej5G0

                  <pathelementpath="${classes}"/>51Testing软件测试网 {i/Z;c9I_ c7i9B

                  <filesetdir="${lib}">

Q$uoT#X"w0

                       <includename="**/*.jar"/>51Testing软件测试网"|G| U ~^ G U3@8c

                  </fileset>51Testing软件测试网b@-S0H7f3d

              </classpath>51Testing软件测试网 VF Kv8ll8}&lU'd-Ve

          </junit>51Testing软件测试网1\1l!B"b-V7IETa

       </target>51Testing软件测试网S)e8J']%^a ~z4w

   </project>51Testing软件测试网?;Igr-rgllFp

4.进入jenkins,新建job,选择增加构建步骤,选择invoke antbuild file输入该build.Xml文件的路径51Testing软件测试网&W!U6o"I'~J

5.增加构建后操作步骤,选择“publish junittest result report“,测试报告栏输入:*.xml,jenkins将会从该jobworkspace(如:D:\jenkins\workspace\anttest)去查找xml格式的junit报告

;\u-wO4p0bK|sC0

6.保存后,构建结果如下:51Testing软件测试网X%Tc E o C@ B!BL

51Testing软件测试网9B{+xG/DU c|G

.JpxCG0diq0

TAG:

 

评分:0

我来说两句

Open Toolbar