1、使用ant对代码进行编译构建,编译到${basedir}/dist目录下,步骤省略。。。
2、单元测试构建脚本,单元测试的classpath需要包含之前编译目录和testcase的编译目录;
<?xml version="1.0" encoding="gbk"?> <project name="test" default="test-basic" basedir="."> <property name="lib.dir" value="${basedir}/WebRoot/WEB-INF/lib"/> <!-- 单元测试目录 --> <property name="junit.dir" value="${basedir}/junit" /> <!-- testcase代码目录 --> <property name="test.dir" value="${basedir}/Test" /> <!-- 源代码编译目录 --> <property name="dist.dir" value="${basedir}/dist"/> <path id="test-classpath"> <fileset dir="${lib.dir}"> <include name="*.jar"/> </fileset> <!-- 源代码编译目录 --> <pathelement location="${dist.dir}/WEB-INF/classes"/> <!-- testcase代码编译目录 --> <pathelement location="${junit.dir}"/> </path> <target name="test-basic"> <mkdir dir="${junit.dir}\report" /> <!-- testcase代码编译 --> <javac srcdir="${test.dir}" destdir="${junit.dir}" debug="on" encoding="UTF-8" debuglevel="${debuglevel}" target="1.6"> <classpath refid="test-classpath" /> </javac> <!-- 单元测试 --> <junit printsummary="false" haltonfailure="false"> <classpath refid="test-classpath" /> <formatter type="brief" usefile="false"/> <formatter type="xml"/> <test todir="${junit.dir}\report" name="test.TestSuite"></test> </junit> <!-- 单元测试报告 --> <junitreport todir="${junit.dir}\report"> <fileset dir="${junit.dir}\report"> <include name="TEST-*.xml"/> </fileset> <report format="frames" todir="${junit.dir}\report" /> </junitreport> </target> </project>
3、Find Bugs
<property name="findbugs.home" value="${basedir}/findbugslib" /> <taskdef name="findbugs" classpath="${basedir}/findbugslib/findbugs-ant.jar" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" /> <target name="FindBugs" description="用Findbugs检查代码错误."> <echo>开始用Findbugs检查代码错误......</echo> <mkdir dir="${junit.dir}\findbugs" /> <findbugs home="${findbugs.home}" output="xml" outputFile="${junit.dir}\findbugs\findbugs_result.xml" jvmargs="-Xmx1024m"> <sourcePath path="${basedir}/src" /> <class location="${dist.dir}/WEB-INF/classes" /> </findbugs> <echo>Findbugs检查代码错误完成......</echo> </target>
findbugslib目录jar包列表:annotations.jar ant.jar ant-contrib-1.0b3.jar asm-3.1.jar asm-commons-3.1.jar asm-tree-3.1.jar bcel.jar commons-lang-2.4.jar dom4j-1.6.1.jar findbugs.jar findbugs-ant.jar jaxen-1.1.1.jar jFormatString.jar jsr305.jar
4、check style
<target name="checkstyle" description="check source format with checkstyle"> <mkdir dir="${check.dir}" /> <taskdef resource="checkstyletask.properties" classpath="${check.lib}/checkstyle-5.6-all.jar" /> <checkstyle failOnViolation="false" config="${basedir}/checklib/test_Check.xml"> <classpath refid="test-classpath" /> <fileset dir="${basedir}/src"> <include name="**/*.java" /> </fileset> <formatter type="xml" toFile="${check.dir}\checkstyle_result.xml" /> </checkstyle> </target>