- 浏览: 148224 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
415421979:
我也遇到了这个问题 求解啊
JBoss/Tomcat 安装路径带空格时 JNDI 无法初始化的BUG -
ivonxiao:
谢谢楼主的分享
异常管理系统 -
ivonxiao:
谢谢楼主的分享~~
Java对象的强、软、弱和虚引用
看标题就知道,这个是开发一个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 –>
<!– =================================================================== –>
<!– - - - - - - - - - - - - - - - - -
target: init
initialize the build env. for code coverage
- - - - - - - - - - - - - - - - - –>
<target name="init-coverage" description="initialize the build env.">
<!– create the output folder –>
<mkdir dir="${instrumented-dir}" />
<mkdir dir="${cobertura-dir}" />
<mkdir dir="${cobertura-xml-dir}" />
<mkdir dir="${cobertura-html-dir}" />
</target>
<target name="compile-coverage" depends="init">
<javac srcdir="${src-dir}:${testcase-dir}" destdir="${out-dir}" debug="true" >
<classpath refid="cobertura.classpath" />
</javac>
</target>
<!– =================================
target: instrument
Instrument into the class files, but
exclude test classes
================================= –>
<target name="instrument" depends="init-coverage,compile-coverage" description="instrument into the class files">
<!–
Instrument the application classes, writing the
instrumented classes into ${instrumented.dir}.
–>
<cobertura-instrument todir="${instrumented-dir}" datafile="${instrument-file}">
<!–
The following line causes instrument to ignore any
source line containing a reference to log4j, for the
purposes of coverage reporting.
–>
<ignore regex="org.apache.log4j.*" />
<fileset dir="${out-dir}">
<!–
Instrument all the application classes, but
don’t instrument the test classes.
–>
<include name="**/*.class" />
<exclude name="**/Test*.class" />
</fileset>
</cobertura-instrument>
</target>
<!– =================================
target: coverage-check
check the code coverage by given rates.
================================= –>
<target name="coverage-check" description="check the code coverage by given rates">
<cobertura-check branchrate="34" totallinerate="100" />
</target>
<!– =================================
target: coverage-report-xml
generate code coverage report by xml format
================================= –>
<target name="coverage-report-xml" description="generate xml report">
<!– Generate an XML file containing the coverage data using the "srcdir" attribute. –>
<cobertura-report srcdir="${src-dir}" destdir="${cobertura-xml-dir}" format="xml" datafile="${instrument-file}"/>
</target>
<!– =================================
target: coverage-report-html
generate code coverage report by html format
================================= –>
<target name="coverage-report-html">
<!–
Generate a series of HTML files containing the coverage
data in a user-readable form using nested source filesets.
–>
<cobertura-report destdir="${cobertura-html-dir}" datafile="${instrument-file}">
<fileset dir="${src-dir}">
<include name="**/*.java"/>
</fileset>
</cobertura-report>
</target>
<!– run the code coverage individual –>
<target name="coverage" depends="compile-coverage,instrument,test,coverage-report-html"
description="Compile, instrument ourself, run the tests and generate JUnit and code coverage reports."/>
<!– =================================================================== –>
<!– Public Targets –>
<!– =================================================================== –>
<target name="clean">
<delete quiet="true" includeEmptyDirs="true">
<fileset dir="${report-dir}">
<exclude name=".cvsignore" />
<exclude name="CVS" />
</fileset>
<fileset dir="${out-dir}">
</fileset>
</delete>
</target>
<!– =================================================================== –>
<!– Global Targets –>
<!– =================================================================== –>
<target name="all" depends="compile" />
<target name="junit" depends="clean, compile-test, test" />
<target name="full" depends="clean, coverage" />
</project>
作者: Cherami
原载: Ant+JUnit+Cobertura
下载下面的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 –>
<!– =================================================================== –>
<!– - - - - - - - - - - - - - - - - -
target: init
initialize the build env. for code coverage
- - - - - - - - - - - - - - - - - –>
<target name="init-coverage" description="initialize the build env.">
<!– create the output folder –>
<mkdir dir="${instrumented-dir}" />
<mkdir dir="${cobertura-dir}" />
<mkdir dir="${cobertura-xml-dir}" />
<mkdir dir="${cobertura-html-dir}" />
</target>
<target name="compile-coverage" depends="init">
<javac srcdir="${src-dir}:${testcase-dir}" destdir="${out-dir}" debug="true" >
<classpath refid="cobertura.classpath" />
</javac>
</target>
<!– =================================
target: instrument
Instrument into the class files, but
exclude test classes
================================= –>
<target name="instrument" depends="init-coverage,compile-coverage" description="instrument into the class files">
<!–
Instrument the application classes, writing the
instrumented classes into ${instrumented.dir}.
–>
<cobertura-instrument todir="${instrumented-dir}" datafile="${instrument-file}">
<!–
The following line causes instrument to ignore any
source line containing a reference to log4j, for the
purposes of coverage reporting.
–>
<ignore regex="org.apache.log4j.*" />
<fileset dir="${out-dir}">
<!–
Instrument all the application classes, but
don’t instrument the test classes.
–>
<include name="**/*.class" />
<exclude name="**/Test*.class" />
</fileset>
</cobertura-instrument>
</target>
<!– =================================
target: coverage-check
check the code coverage by given rates.
================================= –>
<target name="coverage-check" description="check the code coverage by given rates">
<cobertura-check branchrate="34" totallinerate="100" />
</target>
<!– =================================
target: coverage-report-xml
generate code coverage report by xml format
================================= –>
<target name="coverage-report-xml" description="generate xml report">
<!– Generate an XML file containing the coverage data using the "srcdir" attribute. –>
<cobertura-report srcdir="${src-dir}" destdir="${cobertura-xml-dir}" format="xml" datafile="${instrument-file}"/>
</target>
<!– =================================
target: coverage-report-html
generate code coverage report by html format
================================= –>
<target name="coverage-report-html">
<!–
Generate a series of HTML files containing the coverage
data in a user-readable form using nested source filesets.
–>
<cobertura-report destdir="${cobertura-html-dir}" datafile="${instrument-file}">
<fileset dir="${src-dir}">
<include name="**/*.java"/>
</fileset>
</cobertura-report>
</target>
<!– run the code coverage individual –>
<target name="coverage" depends="compile-coverage,instrument,test,coverage-report-html"
description="Compile, instrument ourself, run the tests and generate JUnit and code coverage reports."/>
<!– =================================================================== –>
<!– Public Targets –>
<!– =================================================================== –>
<target name="clean">
<delete quiet="true" includeEmptyDirs="true">
<fileset dir="${report-dir}">
<exclude name=".cvsignore" />
<exclude name="CVS" />
</fileset>
<fileset dir="${out-dir}">
</fileset>
</delete>
</target>
<!– =================================================================== –>
<!– Global Targets –>
<!– =================================================================== –>
<target name="all" depends="compile" />
<target name="junit" depends="clean, compile-test, test" />
<target name="full" depends="clean, coverage" />
</project>
作者: Cherami
原载: Ant+JUnit+Cobertura
发表评论
-
Maven 2.0:编译、测试、部署、运行
2008-01-24 16:55 1314摘要:Maven1.0已经历了几年的时间,并且作为Ant的替代 ... -
使用Jetty和DWR创建伸缩性Comet程序
2008-01-24 16:03 2374异步服务器端事件驱动 ... -
使用MOCK对象进行单元测试
2008-01-24 15:50 11521.出了什么问题? 单元测试的目标是一次只验证一个 ... -
JUnit常用断言方法
2008-01-24 15:35 1178常用的方法如下: assertEquals(a, b) ... -
Junit 的使用经验总结
2008-01-24 15:19 1483经验一、不要在测试用例的构造函数中做初始化 当我们需要增加一个 ... -
J2EE架构的6个最佳实践
2008-01-24 14:39 1156虽然许多文章曾经讨论过J2EE最佳实践。那么,为什么我还要再写 ... -
开发完整J2EE解决方案的八个步骤6
2008-01-24 13:59 829VII、组合和配置 组 ... -
开发完整J2EE解决方案的八个步骤5
2008-01-24 13:55 899IV、对象设计 在体系规范的指导下,设计可在技术上扩展和适 ... -
开发完整J2EE解决方案的八个步骤4
2008-01-24 13:53 1002应用体系 应用体系 ... -
开发完整J2EE解决方案的八个步骤3
2008-01-24 13:51 791III、体系规范 经过前面的两个步骤,商业领域的问题和需求 ... -
开发完整J2EE解决方案的八个步骤2
2008-01-24 13:49 809II、面向对象的分析 分析产生问题域模型:类、对象和交互。 ... -
开发完整J2EE解决方案的八个步骤1
2008-01-24 13:47 1198摘要 Java 2企业 ... -
单元测试策略
2008-01-24 13:27 1318本文为作者在使用Junit ... -
junit基本教程
2008-01-24 13:06 1715Eclipse中配置junit 在要使用JUNIT的 ... -
junit教程
2008-01-24 12:50 4978您是怎样编写测试代码的呢? 在调试器中使用表达式也许是最简单 ... -
junit单元测试的意义
2008-01-24 12:29 2837为什么要进行单测试. 1. ... -
HttpServletRequest对象getParameter()方法在各web容器中返回值问题
2008-01-24 10:04 3065Servlet中HttpServletRequest对象的ge ... -
JBoss/Tomcat 安装路径带空格时 JNDI 无法初始化的BUG
2008-01-08 17:55 2047JBoss/Tomcat 安装路径带空格时 JNDI 无法初始 ... -
J2EE项目异常处理
2008-01-05 17:34 915J2EE项目异常处理 ... -
jndi的命名
2008-01-05 11:26 1056jndi是一种通过名字获取对象的一种技术,一般在java中 ...
相关推荐
总的来说,"Junit+ant+cobertura示例"是一个展示如何使用JUnit进行单元测试,通过Ant进行自动化构建,并利用Cobertura进行代码覆盖率分析的实践案例。这样的组合可以帮助开发者更高效地管理和提升代码质量,确保软件...
在Java开发过程中,Ant和JUnit是两个非常重要的工具。Ant是一个构建工具,它允许开发者自动化构建、测试和部署Java项目,而JUnit则是一个单元测试框架,用于编写和运行可重复的测试用例,确保代码质量。这个“ant+...
SpringBoot简化了Java应用的开发流程,而JUnit是广泛使用的单元测试工具,Log4J则是一款强大的日志记录框架。让我们一起了解如何在实际开发中有效地利用这些技术。 1. **SpringBoot简介**: SpringBoot是由Pivotal...
在本文中,我们将详细介绍如何配置Ant、JUnit和SVN,这三个工具在Java开发中的重要性以及它们的安装过程。 首先,Ant是一个基于Java和XML的构建工具,它的主要功能是管理和自动化项目的构建过程。Ant通过一个名为...
【Ant+JUnit+Svn实现自动单元测试】 Ant是一种流行的Java构建工具,它使用XML格式的构建文件(build.xml)来定义一系列的任务,如编译、打包、测试等,以自动化软件开发过程。Ant的主要优点是它的灵活性和可扩展性...
`Ant` 是一个流行的 Java 构建工具,它允许开发者自动化编译、打包、测试等任务。`JUnit` 则是 Java 平台上的一个单元测试框架,用于编写和执行可重复的测试用例。在这个"Ant+JUnit测试报告实际例子"中,我们将深入...
终极自动化测试环境搭建:Selenium+Eclipse+Junit+TestNG+Python。
在Java开发过程中,构建工具和...这个实例为你提供了一个实际操作的环境,你可以通过修改`build.xml`文件和测试类,进一步了解Ant和JUnit的用法,以及它们在实际项目中的应用。这将有助于提升你的Java开发和测试技能。
本话题将深入探讨如何在Eclipse集成开发环境中利用Ant和JUnit进行项目构建与测试,以提升开发效率和代码质量。 首先,Eclipse是一款广泛使用的Java IDE,它提供了丰富的功能来支持开发人员进行代码编写、调试和项目...
JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage,包含依赖包:junit-jupiter-5.5.1.jar,junit-jupiter-engine-5.5.1.jar,junit-jupiter-params-5.5.1.jar,junit-platform-launcher-1.5.1.jar,junit-...
总结来说,这个项目展示了Java开发中常见的一套技术组合,通过Hibernate和Spring进行数据层和业务层的交互,使用Ant进行构建自动化,利用JUnit保证代码质量,而C标签则提供了用户友好的前端分页体验。这样的组合在...
在Java开发领域,Ant和JUnit是两个不可或缺的工具。Ant是一种基于Java的构建工具,用于自动化项目构建过程,如编译、打包、测试等任务。JUnit则是Java编程语言中最流行的单元测试框架,它使得开发者可以方便地编写和...
标题中的“hibernate+spring+junit+ant+mysql”是一个经典的Java开发组合,它涵盖了五个重要的技术领域:Hibernate作为对象关系映射框架,Spring作为全面的轻量级框架,JUnit用于单元测试,Ant作为构建工具,以及...
1.4.2 JSP(Java服务页面) 1.4.3 EJB(企业JavaBean) 1.4.4 JDBC(Java数据库连接) 1.4.5 JTA/JTS(Java事务) 1.4.6 JNDI(Java命名和目录服务) 1.4.7 JavaMail(Java邮件服务) 1.4.8 RMI(远程方法调用) ...
《Maven2.Ant.Junit合集》是一个包含多种IT工具和框架的资源包,主要聚焦于Java开发中的构建管理和单元测试。这个合集提供了PDF和CHM两种格式的文档,便于不同用户根据个人喜好进行阅读。以下是这些工具及其重要知识...