通过Ant运行单个测试用例并添加JVM参数<转>
<fail message="You must run this target with -Dtest=TestName"/>
</target>
<target name="ensure-jvmarg" unless="jvm.arg">
<fail message="You must run this target with -Djvm.arg=args"/>
</target>
<target name="runtest" depends="compile, ensure-test-name,ensure-jvmarg">
<junit printsummary="withOutAndErr" fork="yes" timeout="6000">?
<classpath refid="junit.classpath" />
<formatter type="plain" usefile="false"/>
<batchtest>
<fileset dir="src/test">
<include name="**/${test}.java"/>
</fileset>
</batchtest>
<jvmarg value="${jvm.arg}"/>
</junit>
</target>
?
?
?
运行命令为:
ant runtest -f your_build.xml?-Dtest=XXXTest -Djvm.arg="-agentlib:xxxagent -Xmx128m"
-f指定build.xml的目录,-Dtest为所要运行的Testcase文件,程序为在src/test(位于junit->batchtest->fileset标签下,可自定义)这个目录下寻找以包含XXXTest的java文件(可用通配符作为输入)。-Djvm.arg即为输入的jvm参数。
update:
timeout参数可指定一个时间(以毫秒计数),超过此时间自动kill该进程。
?
?
?