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

 

  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);
}
}
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);
}
}