一、环境准备

  1. Jenkins:
    1. 到官网下载jenkins.war包:http://jenkins-ci.org/
    2. 安装方法有两种:
      1. 把下载下来的jenkins.war包放到文件夹下,如C:\jenkins,然后打开命令行窗口并进到该目录下,执行java -jar jenkens.war命令,当提示:“Jenkins is fully up and running”时,表示启动成功,这时在浏览器窗口输入:http://localhost:8080/ 就可到jenkins的首页。
      2. 如果有tomcat,把jenkins.war包放在tomcat的webapps文件夹下,启动tomcat时会自动启动jenkins,这时通过http://localhost:8080/jenkins就 可以访问jenkins的首页了。
  2. ANT:

      下载ant并配置ANT_HOME,官网:http://ant.apache.org/

  3、Junit:

      下载junit.jar包,没用过的可参考:http://blog.csdn.net/lengyuhong/article/details/5815017

  4、SVN:

      1、用本地硬盘当SVN仓库:http://wenku.baidu.com/view/12b02f6a011ca300a6c39081.html

      2、SVN服务器搭建和使用:http://www.cnblogs.com/xiaobaihome/tag/SVN/ (推荐用此种方法,后面有原因)

二、项目代码:

  环境准备好了之后就可开始写代码、单元测试案例以及ANT用来构建的build.xml文件,这些内容在上一篇ANT task之Junit、JunitReport有讲过,这里不细讲:

1、Java代码:

package com.glen.he;

public class ComplexCalculation {
public int Division(int a,int b){
return (a/b);
} public int Multiply(int a,int b){
return (a*b);
}
}

ComplexCalculation.java

package com.glen.he;

public class SimpleCalculation {
public int Add(int a,int b){
return (a+b);
} public int Subtration(int a,int b){
return(a-b);
} }

SimpleCalculation.java

2、单元测试代码:  

package com.glen.he;

import com.glen.he.ComplexCalculation;

import static org.junit.Assert.*;

import org.junit.Test;

public class ComplexCalculationTest {

    ComplexCalculation cc = new ComplexCalculation();

    @Test
public void DivisionTest() { int c = cc.Division(100, 5); assertEquals(20, c);
} @Test
public void MultiplyTest() { int c = cc.Multiply(100, 5); assertEquals(500, c);
}
}

ComplexCalculationTest.java

package com.glen.he;

import com.glen.he.SimpleCalculation;

import static org.junit.Assert.*;
import org.junit.Test; public class SimpleCalculationTest { SimpleCalculation sc = new SimpleCalculation(); @Test
public void AddTest() { int c = sc.Add(3, 5); assertEquals(8, c);
} @Test
public void SubtrationTest() { int c = sc.Subtration(20, 5); assertEquals(15, c);
}
}

SimpleCalculationTest.java

3、build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="AntDemo" default="junit" basedir=".">
<!-- =================================================================== -->
<!-- 变量设置 -->
<!-- =================================================================== --> <!-- 源代码src路径 -->
<property name="src.path" value="src/java"/>
<!-- 单元测试代码路径 -->
<property name="test.path" value="src/test"/>
<!-- 编译文件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 -->
<!-- =================================================================== -->
<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}"/>
<mkdir dir="${dist.path}"/>
</target> <!-- =================================================================== -->
<!-- 清除历史编译class -->
<!-- =================================================================== -->
<target name="clean" description="clean">
<delete dir="${build.path}"/>
<delete dir="${report.path}"/>
<delete dir="${dist.path}"/>
</target> <!-- =================================================================== -->
<!-- 编译测试文件,初始化目录 -->
<!-- =================================================================== -->
<target name="compile" depends="init">
<javac srcdir="${src.path}" destdir="${build.path}" classpathref="compile.path" includeantruntime="true"/>
<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}" />
</junitreport>
</target> <target name="make-jar" depends="compile" description="make jar file">
<jar jarfile="${dist.path}/AntDemo.jar">
<fileset dir="${build.path}"> <!--除去test文件-->
<exclude name="**/*Test.class"/>
</fileset>
</jar>
</target> </project>

build.xml

三、配置Jenkins:

  PS:Jenkins可以通过master/slave来支持分布式的job运行,本文运行在master,即Jenkins所在的机器。

  1、打开jenkins首页,新建一个job,输入Item名称,选择 构建一个自由风格的软件项目,点击"OK"  

  2、在 源码管理 那里,选择Subversion,在Repository URL后面,输入你的SVN地址。

      PS:Repository URL使用本地磁盘当仓库这种方法后来我在其它机器上试验时,发现老是报错:svn: E180001: Unable to open an ra_local session to URL。一时没有找到解决办法,大家如果也碰到此问题,可以搭建SVN服务器来管理源代码,我试了,挺好使的。

  3、在 构建 那里也可以有两种做法:

   I、选择Execute Windows batch command,在输入框输入如下命令(这里我选择的是这个方法):

      set path=C:\ANT_HOME\Apache-Ant-1.7.0\bin;path  把ant的安装目录添加到path

      ant junit                        执行junit task      

   II、方法I比较麻烦,如果我们设置好了ANT_HOME,可以选择Invoke Ant,然后在targets里面指定我们build.xml里的task name。       

  4、点击保存,然后选择立即构建,执行结果:  

参考资料:

http://hi.baidu.com/janice515/item/3272fe9b99eb4cc8b6253101 

http://blog.csdn.net/lengyuhong/article/details/5828770

搭建持续集成单元测试平台(Jenkins+Ant+Java+Junit+SVN)的更多相关文章

  1. jmeter --- 搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)

    jmeter --- 搭建持续集成接口测试平台(Jenkins+Ant+Jmeter) 一.环境准备: 1.JDK:http://www.oracle.com/technetwork/java/jav ...

  2. 搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)

    一.环境准备: 1.JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.Jmeter:http://jme ...

  3. 【jmeter】搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)

    一.环境准备: 1.JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.Jmeter:http://jme ...

  4. 搭建持续集成接口测试平台(jenkins+ant+jmeter)

    一.环境准备: 1.JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.Jmeter:http://jme ...

  5. 【iOS】Jenkins Gitlab持续集成打包平台搭建

    Jenkins Gitlab持续集成打包平台搭建 SkySeraph July. 18th 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph个人站点: ...

  6. Jenkins Gitlab持续集成打包平台搭建

    http://www.cnblogs.com/skyseraph/p/5695021.html 1. 相关概念 Jenkins Jenkins,一个用Java编写的开源的持续集成工具,提供了软件开发的 ...

  7. 使用 Jenkins 搭建 iOS/Android 持续集成打包平台【转】

    背景描述 根据项目需求,现要在团队内部搭建一个统一的打包平台,实现对iOS和Android项目的打包.而且为了方便团队内部的测试包分发,希望在打包完成后能生成一个二维码,体验用户(产品.运营.测试等人 ...

  8. Jmeter+Ant+Jenkins搭建持续集成的接口测试框架

    https://my.oschina.net/hellotest/blog/516079 摘要: 一个系统通常有多个接口,软件的生命周期中,我们会不断的去优化老的接口和开发新的接口,那么在这个过程中, ...

  9. Jenkins 快速搭建持续集成环境

    持续集成概述 什么是持续集成 随着软件开发复杂度的不断提高,团队开发成员间如何更好地协同工作以确保软件开发的质量已经慢慢成为开发过程中不可回避的问题.尤其是近些年来,敏捷(Agile) 在软件工程领域 ...

随机推荐

  1. Java Calendar,Date,DateFormat,TimeZone,Locale等时间相关内容的认知和使用(7) TimeZone

    本章介绍TimeZone. TimeZone 简介 TimeZone 表示时区偏移量,也可以计算夏令时.在操作 Date, Calendar等表示日期/时间的对象时,经常会用到TimeZone:因为不 ...

  2. 【ELK】【docker】6.Elasticsearch 集群启动多节点 + 解决ES节点集群状态为yellow

    本章其实是ELK第二章的插入章节. 本章ES集群的多节点是docker启动在同一个虚拟机上 ====================================================== ...

  3. ArcGIS教程:树状图

    摘要 构造可显示特征文件里连续合并类之间的属性距离的树示意图(树状图). 使用方法 · 输入特征文件必须採用预定的特征文件格式. 特征文件可使用 Iso 聚类或创建特征工具来创建.该文件必须至少包括两 ...

  4. Java中线程池,你真的会用吗?

    在<深入源码分析Java线程池的实现原理>这篇文章中,我们介绍过了Java中线程池的常见用法以及基本原理. 在文中有这样一段描述: 可以通过Executors静态工厂构建线程池,但一般不建 ...

  5. [转]nginx下的url rewrite

    转:http://zhengdl126.iteye.com/blog/698206 if (!-e $request_filename){rewrite "^/index\.html&quo ...

  6. gunicorn结合django启动后台线程

    preload 为True的情况下,会将辅助线程或者进程开在master里,加重master的负担(master最好只是用来负责监听worker进程) django应用的gunicorn示例:只在主线 ...

  7. 数据库分库分表中间件:Mycat;分布式数据库;mysql的分布式事务

    官网:http://mycat.io/,里面有电子书籍可以下载:http://www.mycat.io/document/mycat-definitive-guide.pdf 旧版本下载地址:http ...

  8. you have mixed tabs and spaces fix this

    http://blog.csdn.net/tonyyan19781/article/details/60882443 Vs2013 IDE下,编辑C++的工程源码,在打开文件的时候,会出现 " ...

  9. 深度学习Github排名,很不错的介绍

    今天看到这篇文章,把深度学习github排名靠前的项目,介绍了一下,很不错: https://blog.csdn.net/yH0VLDe8VG8ep9VGe/article/details/81611 ...

  10. 在PC上像普通winform程序调试WINCE程序

    在PC上像普通winform程序调试WINCE程序 步骤: 1. 在VS2008中到 工具→选项→设备工具→设备,选择对应的平台,另存为新的名称,如CEDesktopRun,关闭VS2008.(如果不 ...