我在ant中有一些测试用例,每个测试用ping一个URL,我有一个java类,它正在执行ping URL并处理我的测试用例需要的东西,我正在编译和从我的ant构建文件中运行该java类。
所有测试用例的URL都不同,所以我想将URL从ant文件传递给java类,但是我很难做到这一点,是否有人有任何建议如何将变量从ant传递给java类。现在我将java文件中的URL传递给一个测试用例,但我不想为每个测试用例创建不同的java文件,只是每次都有不同的URL。
这是我的testcase 1目标,它调用ping目标:
<target name="01">
<description>
@testlogic.group type="category" values="mats"
Incremental response data stress test, multi-thread model
</description>
<antcall target="pingOHSJava">
<param name="out.log" value="tiapwt01.log"/>
<param name="ohs.name" value="ohs1"/>
<param name="url" value="/waiter/servlet/ServletStressMulti?mode=1"/>
<param name="para1" value="1"/>
<param name="para2" value="10"/>
<param name="para3" value="100"/>
<param name="para4" value="10"/>
</antcall>
<fail message="test FAILED found.. failing">
<condition>
<resourcecontains resource="${tiapwt.base.dir}/common/output/tiapwt_content.txt" substring="FAILED"/>
</condition>
</fail>
</target>
这是ping目标:
<target name="pingOHSJava">
<property name="srcdir" location="${functional.base.dir}/tiapwt/common/java" />
<path id="classpath.test">
<pathelement location="/scratch/skaneria/Dwnld/junit-4.10.jar" />
</path>
<property name="lib.dir" value="../common/jars" />
<taskdef resource="org/testlogic/toolkit/asserts/antlib.xml">
<classpath>
<fileset dir="${lib.dir}" includes="tlt-asserts-0.3.jar" />
</classpath>
</taskdef>
<delete verbose="true">
<fileset dir="${srcdir}" includes="**/*.class" />
</delete>
<property name="urlPing" value="http://${ADMIN_HOST}:${APACHE_PORT}${url}"/>
<trycatch property="pingOutput">
<try>
<javac srcdir="${srcdir}" destdir="${srcdir}">
<classpath refid="classpath.test"/>
</javac>
<java classname="HttpURLConnectionExample" fork="true" failonerror="true">
<classpath path="${srcdir}"/>
</java>
</try>
<finally>
<echo file="${twork.dir}/${out.log}" append="false">
URL: ${urlPing}
parameter 1 : mode=${para1}
parameter 2 : iterations=${para2}
parameter 3 : initial=${para3}
parameter 4 : increment=${para4}
------------------------------------------
${pingOutput}
</echo>
</finally>
</trycatch>
</target>
这是java类中使用URL的片段:
private void sendGet() throws Exception {
String url = "http://slc06mwj.us.oracle.com:7777/waiter/servlet/ServletStressMulti?mode=1&iterations=10&initial=100&increment=10000";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);
try{
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
System.out.println("Response Message : " + con.getResponseMessage());
} catch(Exception e){
System.out.println("error");
}