注册本站  论坛  繁體中文

电脑技巧
手机 | MP3 | MP4 | 显卡 | 主板 | 显示器 | 光存储 | 笔记本 | 网络设备 | 移动存储 | 数码相机
键鼠 | CPU | 音箱 | GPS | 电视 | 服务器 | 投影机 | 机箱电源 | 品牌电脑 | 办公打印 |
| 网站首页 | Cisco | Windows | Linux | Java | Dotnet | Oracle | 网页设计 | 平面设计 | 安全 | 软件应用 | 电脑维修 | 办公维修 |
您现在的位置: 电脑技巧 >> Java >> 开源技术 >> ANT >> Java正文

Java应用利器组合:Ant+JUnit+Cobertura

文章来源:中国IT实验室收集整理 作者:Cherami 更新时间:2007-1-6 【 】 【加入收藏

    看标题就知道,这个是开发一个Java应用的利器组合,使用Ant完成工程的构建(Build),使用JUnit完成单元测试,使用Cobertura完成代码覆盖测试,也可以辅助查找性能瓶颈和一些类型的BUG,下面是一个完整的build.xml范例,可以完全拿来用,不需任何修改,只要你的目录和这里的目录一致(应该也是很通用的):

下载下面的build.xml文件

文件内容:
<project default="all">
    <!– =================================================================== –>
    <!–                               Definitions                           –>
    <!– =================================================================== –>   
    <property name="base-dir" location="." />
    <property name="lib-dir" location="${base-dir}/lib" />
    <property name="src-dir" location="${base-dir}/src" />
    <property name="testcase-dir" location="${base-dir}/test" />
    <property name="out-dir" location="${base-dir}/classes" />
    <property name="report-dir" location="${base-dir}/report" />
    <property name="junit-dir" location="${report-dir}/junit" />
    <property name="junit-xml-dir" location="${junit-dir}/xml" />
    <property name="junit-html-dir" location="${junit-dir}/html" />
    <property name="cobertura-dir" location="${report-dir}/cobertura" />
    <property name="cobertura-xml-dir" location="${cobertura-dir}/xml" />
    <property name="cobertura-html-dir" location="${cobertura-dir}/html" />
    <property name="instrumented-dir" location="${report-dir}/instrumented" />
    <property name="instrument-file" location="${instrumented-dir}/cobertura.ser" />
    <property name="cobertura.dir" value="${instrumented-dir}" />
   
   
    <path id="classpath.all">
        <pathelement location="${out-dir}" />
        <fileset id="alljars" dir="${lib-dir}">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <!– include the cobertura building jars –> 
    <path id="cobertura.classpath">
        <path refid="classpath.all" />
    </path>   
   
    <!– define the cobertura property file –> 
    <taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
   
    <!– =================================================================== –>
    <!–                            Project Targets                          –>
    <!– =================================================================== –>
   
    <target name="init" description="initialize the project env.">
        <!– create the output folder –> 
        <mkdir dir="${out-dir}" />
        <mkdir dir="${report-dir}" />
        <copy todir="${out-dir}">
            <fileset dir="${src-dir}" includes="**/*.properties" />
        </copy>
    </target>

     <target name="compile" depends="init">
        <javac srcdir="${src-dir}" destdir="${out-dir}">
            <classpath refid="classpath.all" />
        </javac>
    </target>
  
    <!– =================================================================== –>
    <!–                            Unit Test Targets                        –>
    <!– =================================================================== –>
   
    <!– - - - - - - - - - - - - - - - - -
      target: init
      initialize the build env            
    - - - - - - - - - - - - - - - - - –>   
    <target name="init-test" description="initialize the test env.">
        <!– create the output folder –> 
        <mkdir dir="${junit-dir}" />
        <mkdir dir="${junit-xml-dir}" />
        <mkdir dir="${junit-html-dir}" />
    </target>

    <!– - - - - - - - - - - - - - - - - -
      target: compile-test
      compile the test cases                
    - - - - - - - - - - - - - - - - - –>    
    <target name="compile-test" depends="compile">
        <javac srcdir="${testcase-dir}" destdir="${out-dir}">      
            <classpath refid="classpath.all" />
        </javac>
    </target>

    <!– =================================
      target: test
      run the unit test
     ================================= –>   
    <target name="test" depends="init-test">
        <junit fork="yes" printsummary="on" maxmemory="100m">
            <sysproperty key="net.sourceforge.cobertura.datafile"
                file="${instrument-file}" />

            <classpath location="${instrumented-dir}" />
            <classpath refid="cobertura.classpath" />
                  
            <formatter type="xml" />
            <batchtest todir="${junit-xml-dir}">
                <fileset dir="${out-dir}">
                    <include name="**/Test*.class" />
                    <exclude name="**/*$*.class" />
                </fileset>
            </batchtest>
        </junit>
        <junitreport todir="${junit-xml-dir}">
            <fileset dir="${junit-xml-dir}">
                <include name="TEST-*.xml" />
            </fileset>
            <report format="frames" todir="${junit-html-dir}" />
        </junitreport>
    </target>
   
    <!– =================================================================== –>
    <!–                      Code Coverage Targets                          –>
    <!– =================================================================== –>
   

  • 上一篇Java:

  • 下一篇Java: 没有了
  • 最 新 热 门
     如何在MyEclipse快速搭建Hibernate应用
     spring aop中单独代理和自动代理的设置
     Nhibernate与代码生成器介绍
     Java多线程同步设计中使用Metux
     讨论5种跟踪Java执行的方法
     在Eclipse中使用SWT进行界面设计
     Spring 结合 Hibernate 配置 C3P0
     开发不再是苦差事 用Eclipse简化开发
     解决运行eclipse内存不足的问题
     利用Ecipse生成Javadoc乱码解决方法
    最 新 推 荐
     Java应用利器组合:Ant+JUnit+Cobertura
     使用ant编译打包应用程序
     ant的一些偏门技巧
     Antlr入门详细教程
     ant+cactus+tomcat5.5容器内单元测试
     使用Ant进行增量快速构建实现
     Ant+JMeter进行Web应用的稳定性测试
     关于build tool的构想--从ant说起
     Weblogic Server ant开发Web Service二(图)
     Weblogic Server ant开发Web Service一(图)
    相 关 文 章

    Java多线程同步设计中使用Metux
    讨论5种跟踪Java执行的方法
    利用Ecipse生成Javadoc乱码解决方法
    java基础入门之Hibernate 入门
    关于 JavaWebFrameWork 的选择
    如何实现XML+XSL+javascript数据排序
    Javascript+DOM访问XML文件数据实例
    javascript+xml实现二级下拉菜单二
    javascript+xml实现二级下拉菜单一
    在Java Web框架中创建VoiceXML页面

    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告

     

    Copyright 2006-2008 pcjx.com All Rights Reserved
    电脑技巧 版权所有 粤ICP备06059145号 地图
    本网站所有内容未经许可不得转载或做其他使用