|
一、ant
1、上apache下载稳定的ant版本
2、ant的使用
1)、解压缩ant,并将解压以后bin目录中的ant.bat文件的路径加入到系统变量path中去!
2)、ant运行命令批处理,而且是跨平台的,所以比dos批处理更有效!
3)、需要有build.xml规定如何去编译
<?xml version="1.0" encoding="UTF-8" ?>
- <project name="HelloWorld" default="run" basedir=".">
<property name="src" value="." />
<property name="dest" value="classes" />
<property name="hello_jar" value="hello.jar" />
- <target name="init">
<mkdir dir="${dest}" />
</target>
- <target name="compile" depends="init">
<javac srcdir="${src}" destdir="${dest}" />
</target>
- <target name="build" depends="compile">
<jar jarfile="${hello_jar}" basedir="${dest}" />
</target>
- <target name="run" depends="build">
<java classname="HelloWorld" classpath="${hello_jar}" />
</target>
</project>
project里面包含很多target
property用来定义变量,方便批量修改
target最好互相依赖,检查时比较好检查
常见的target一般命名有以下几种
compile,build,deploy部署,doc生成javadoc,run运行(比较少见)
二、junit
1、原代码
//将字符串倒转
public class StringReverse {
public String reverse(String str){
String temp = "";
for(int i=str.length()-1;i>=0;i--){
temp = temp + str.charAt(i);
}
return temp;
}
}
2、eclipse新建junit
file-->new-->new junit test--->选择需要测试的类方法--->生成测试类框架(然后修改)
3、import junit.framework.TestCase;
//框架可以为每一个测试函数生成对象,在测试之前调用setUp,测试之后调用tearDown
public class StringReverseTest extends TestCase {
StringReverse sr;
public StringReverseTest() {//构造函数
System.out.println("构造函数");
}
protected void setUp() throws Exception {//setUp,父类重写,作初始化的工作(一般指下文一系列测试函数的公共方法,
如数据库连接等)
System.out.println("setUp函数");
sr = new StringReverse();
}
public void testReverse() {//测试函数,以test开头
System.out.println("testReverse函数");
TestCase.assertEquals("anihC",sr.reverse("China"));//(预期结果和实际执行结果是否一致)
}
protected void tearDown() throws Exception {//tearDown,父类重写,作收尾工作(也是指各个测试函数的收尾公共部分)
System.out.println("tearDown函数");
sr = null;
}
}
三、tomcat配置(参考pdf) |
|
|
|
|
|
|