二.ant脚本
只摘取关键部分
<project basedir="." default="deploy-test" name="sanitation">
<target name="deploy-test" depends="quickstart,fun-test,test" />
<!-- ===================================
把打包的文件拷贝到tomcat目录下
==================================== -->
<target name="quickstart" depends="war" description="santation程序">
<echo message="打包部署开始..." />
<antcall target="tomcat.stop" />
<delete dir="${server.deploy}/${ant.project.name}" />
<delete file="${server.deploy}/${ant.project.name}.war" />
<copy todir="${server.deploy}" file="${release.warfile}" />
<echo message="打包部署结束..." />
</target>
<!-- 执行Selenium Web功能测试 -->
<target name="fun-test" depends="compile">
<path id="selenium.server.runtime">
<fileset dir="lib/test" includes="selenium-server-*.jar" />
</path>
<delete dir="${functional_test.data}/**" />
<antcall target="tomcat.start" />
<antcall target="selenium.server.start" />
<junit printsummary="yes" fork="true" errorProperty="test.failed" failureProperty="test.failed">
<classpath>
<path refid="test.classpath" />
<path location="${test.build}" />
</classpath>
<formatter type="xml" />
<formatter type="brief" usefile="false" />
<test name="${testcase}" if="testcase" />
<batchtest todir="${functional_test.data}" unless="testcase">
<fileset dir="${test.build}">
<include name="**/view/*Test.class" />
</fileset>
</batchtest>
</junit>
<antcall target="tomcat.stop" />
<if>
<istrue value="${test.failed}" />
<then>
<functional_test-report report.dir="${functional_test.report}" data.dir="${functional_test.data}" />
<fail>Unit tests 失败. 请于${functional_test.report}目录观看错误信息报表.</fail>
</then>
</if>
</target>
<!-- 执行JUNIT功能测试 -->
<target name="test" depends="compile">
<!-- 检查 junit.jar -->
<available classname="junit.framework.TestCase" property="junit.present" />
<fail unless="junit.present" message="Please copy lib/junit-3.8.1.jar into env.ANT_HOME/lib or Class Path" />
<!-- 清除上次的data数据 -->
<delete dir="${test.data}" />
<mkdir dir="${test.data}" />
<!-- 执行测试 -->
<junit printsummary="yes" fork="true" errorProperty="test.failed" failureProperty="test.failed">
<classpath>
<path refid="test.classpath" />
<path location="${test.build}" />
</classpath>
<formatter type="xml" />
<formatter type="brief" usefile="false" />
<!-- 执行单个或批量的test case。
如果在命令行有定义testcase,
如: ant -Dtestcase=com.gresoft.sanitation.test.MyTestCase
则执行单个test case. -->
<test name="${testcase}" if="testcase" />
<batchtest todir="${test.data}">
<fileset dir="${test.build}">
<exclude name="**/functional/**/*Test.class" />
<exclude name="**/view/*Test.class" />
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
<if>
<istrue value="${test.failed}" />
<then>
<test-report report.dir="${test.report}" data.dir="${test.data}" />
<fail>Unit tests 失败. 请于${test.report}目录观看错误信息报表.</fail>
</then>
</if>
</target>
<target name="deploy-test" depends="quickstart,fun-test,test" />
<!-- ===================================
把打包的文件拷贝到tomcat目录下
==================================== -->
<target name="quickstart" depends="war" description="santation程序">
<echo message="打包部署开始..." />
<antcall target="tomcat.stop" />
<delete dir="${server.deploy}/${ant.project.name}" />
<delete file="${server.deploy}/${ant.project.name}.war" />
<copy todir="${server.deploy}" file="${release.warfile}" />
<echo message="打包部署结束..." />
</target>
<!-- 执行Selenium Web功能测试 -->
<target name="fun-test" depends="compile">
<path id="selenium.server.runtime">
<fileset dir="lib/test" includes="selenium-server-*.jar" />
</path>
<delete dir="${functional_test.data}/**" />
<antcall target="tomcat.start" />
<antcall target="selenium.server.start" />
<junit printsummary="yes" fork="true" errorProperty="test.failed" failureProperty="test.failed">
<classpath>
<path refid="test.classpath" />
<path location="${test.build}" />
</classpath>
<formatter type="xml" />
<formatter type="brief" usefile="false" />
<test name="${testcase}" if="testcase" />
<batchtest todir="${functional_test.data}" unless="testcase">
<fileset dir="${test.build}">
<include name="**/view/*Test.class" />
</fileset>
</batchtest>
</junit>
<antcall target="tomcat.stop" />
<if>
<istrue value="${test.failed}" />
<then>
<functional_test-report report.dir="${functional_test.report}" data.dir="${functional_test.data}" />
<fail>Unit tests 失败. 请于${functional_test.report}目录观看错误信息报表.</fail>
</then>
</if>
</target>
<!-- 执行JUNIT功能测试 -->
<target name="test" depends="compile">
<!-- 检查 junit.jar -->
<available classname="junit.framework.TestCase" property="junit.present" />
<fail unless="junit.present" message="Please copy lib/junit-3.8.1.jar into env.ANT_HOME/lib or Class Path" />
<!-- 清除上次的data数据 -->
<delete dir="${test.data}" />
<mkdir dir="${test.data}" />
<!-- 执行测试 -->
<junit printsummary="yes" fork="true" errorProperty="test.failed" failureProperty="test.failed">
<classpath>
<path refid="test.classpath" />
<path location="${test.build}" />
</classpath>
<formatter type="xml" />
<formatter type="brief" usefile="false" />
<!-- 执行单个或批量的test case。
如果在命令行有定义testcase,
如: ant -Dtestcase=com.gresoft.sanitation.test.MyTestCase
则执行单个test case. -->
<test name="${testcase}" if="testcase" />
<batchtest todir="${test.data}">
<fileset dir="${test.build}">
<exclude name="**/functional/**/*Test.class" />
<exclude name="**/view/*Test.class" />
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
<if>
<istrue value="${test.failed}" />
<then>
<test-report report.dir="${test.report}" data.dir="${test.data}" />
<fail>Unit tests 失败. 请于${test.report}目录观看错误信息报表.</fail>
</then>
</if>
</target>
此脚本主要目的是自动从svn服务器上更新最新程序并进行编译,部署,selenium页面测试,junit功能测试的过程,并自动把运行后结果以邮件形式进行提醒,这样整个流程就算结束,然后一小时后cc自动进行下一次的自动构建过程
问题:其中脚本中 <antcall target="tomcat.stop" />是过程中必须要加入的,如果脚本执行完tomcat还没关闭,cc会一直处于停止状态,一小时后也不会继续轮循,因为它需要等待一个返回信息目前这好象是cc一个bug
好处:使用此方式可以每小时能跟踪项目中各组员项目开发情况,并对系统功能进行持续测试,把问题可以及时进行反馈以便解决,其中项目中测试完整性是整个过程的最关键部分,测试完整加上持续集成工具就可以达到项目自动构建集成功能
这是自己一些简要的步骤,如大家有兴趣我可以以后提供更为详细的步骤!