rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » Java综合

ant+junit实现自动化测试

今天分享以下自己配置wtp(eclipse)+ant+junit实现自动化测试1:下载ant配置ant_home变量和java_home的配置类似,然后在path中加上%ant_home%\bin(执行ant时要用的)在eclipse中设置ant的runtime指向ant_home最好时把junit.jar加在%ant_home%\lib下面,配置的工作就差不多完成了2:下面开始建立一个新的类package com.my;

/**
* @author chens */
public class AddO {      * @param x
     * @param y
     * @return public int add(int x,int y){
     return x+y;
}

}然后建立一个测试类package com.test;

import com.my.AddO;

import junit.framework.TestCase;

public class AddOTest extends TestCase {
AddO a=null;
protected void setUp() throws Exception {
     super.setUp();
     a=new AddO();
}

protected void tearDown() throws Exception {
     super.tearDown();
     a=null;
}

public void testAdd() {
     this.assertEquals(a.add(30, 30),60); }

}
再利用工具建立一个xml文件<?xml version="1.0"?>
<!-- ======================================================================
       2007/05/14 17:42:54                                                        

       project    
       description        chens                                                                
       ====================================================================== -->
<project name="test" default="compile" basedir=".">
<property name="work.location" location=".">
</property>
<property name="src.dir" value=".">
</property>
<property name="classes.dir" value="classes">
</property>
<property name="lib.dir" value="lib">
</property>
<property name="doc.dir" value="doc">
</property>
<property name="project Name" value="test">
</property>
<property name="docName" value="document of test">
</property>
<target name="init">
    <mkdir dir="${work.location}/classes" />
    <mkdir dir="${work.location}/doc" />
    <mkdir dir="${work.location}/dist" />
    <mkdir dir="${work.location}/lib" />
</target>
<target name="compile" depends="init" description="compile the source">
    <javac srcdir="${work.location}" destdir="${work.location}/${classes.dir}">
    </javac>
</target>
<target name="junit" depends="compile">
    <junit printsummary="true">
     <!--
        <classpath path="${run.classpath}"></classpath>
        -->
     <test name="com.test.AddOTest">
     </test>
    </junit>
</target>
<target name="javadoc">
    <javadoc sourcepath="${work.location}" packagenames="com.*" destdir="${work.location}/doc" author="true" public="true" source="1.5" use="true" windowtitle="${Project Name}API" doctitle="${docname}">
     <fileset dir="${work.location}" defaultExcludes="true">
      <include name="***.java" />
     </fileset>
    </javadoc>
</target>
<target name="clean">
    <delete dir="${work.location}/classes">
    </delete>
    <delete dir="${work.location}/doc">
    </delete>
    <delete dir="${work.location}/dist">
    </delete>
    <delete dir="${work.location}/lib" />
</target>
<target name="usage">
    <echo message="Build file of ${Project Name}" />
    <echo message="=============================" />
    <echo message="avalable targets are as follow:" />
    <echo message="init->create directorys in use of building process" />
    <echo message="compile -> compile the source code" />
    <echo message="makejar->generates the jar file" />
    <echo message="javadoc->generates the api documentation" />
    <echo message="clean-> clean up the directory" />
    <echo message="***********************************************" />
    <echo message="use jdk1.5 to build ant" />
    <echo message="see the comments inside the build.xml file for more details" />
    <echo message="=====================================================" />
    <echo message="" />
</target>

</project>然后运行ant就可以了

顶一下
(0)
踩一下
(0)