一、媒介
在二十三天中我们先容了利用maven来下载工程的依赖库文件,用ant来举办war包的成立。本日我们在这个基本大将利用junit+dbunit来举办带有单位测试陈诉的框架的架构。
方针:
二、Junit+Ant生成的单位测试陈诉
<target name="junitreport">
<junit printsummary="on" haltonfailure="false" failureproperty="tests.failed" showoutput="true">
<classpath>
<pathelement path="${dist.dir}/${webAppQAName}/WEB-INF/classes" />
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<fileset dir="${ext-lib.dir}">
<include name="*.jar" />
</fileset>
</classpath>
<formatter type="xml" />
<batchtest todir="${report.dir}">
<fileset dir="${dist.dir}/${webAppQAName}/WEB-INF/classes">
<include name="org/sky/ssh/ut/Test*.*" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${report.dir}">
<fileset dir="${report.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="report" />
</junitreport>
<fail if="tests.failed">
---------------------------------------------------------
One or more tests failed, check the report for detail...
---------------------------------------------------------
</fail>
</target>
在一般的产物级开拓时可能是带有daily building/nightly building的项目组中我们常常需要查抄最新check in的代码是否影响到了原有的工程的编译,因为天天都有措施员往源码处事器里check in代码,而有时我们常常会遇到方才被check in的代码在该措施员当地跑的好好的,可是check in源码处事器上后别人从源码处事器“拉”下来的最新代码跑不起来,甚至编译堕落,这就是regression bug,因此我们天天的打包要干的工作应该是:
三、如安在Spring下书写一个单位测试要领
3.1利用spring的注入特性书写一个单位测试
Spring是一个好对象,一切依赖注入,连单位测试都酿成了依赖注入了,这省去我们许多贫苦。 我们可以将web工程中的applicationContext、Datasource甚至iBatis可能是Hibernate的配署都可以注入给junit,这样使得我们可以用IoC的要领来书写我们的单位测试类。 此处,我们利用的junit为4.7, 而相关的spring-test库文件为3.1,我都已经在pom.xml文件中注明白. 我们先在eclipse里成立一个专门用来放单位测试类的src folder:test/main/java。 留意一下单位测试类的coding convention: