1 2 3 4 5 | <target name="runUT"> <exec executable=" C:\Program Files\Mozilla Firefox\firefox.exe"> <arg value="http://localhost/runner.html"/> </exec> </target> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class ResultService extends ReqExecutor { private String result = ""; public ReqExecutor newInstance() { return this ; } public HTTPResponse execute(HTTPRequest req) { String body = req.getBody(); if(body != null && !body.trim().equals("")) result = body; else { return new StringResponse(result); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | doh._report = function (){ this .debug("| TEST SUMMARY:"); this .debug(this ._line); this .debug("\t", this ._testCount, "tests in", this ._groupCount, "groups"); this .debug("\t", this ._errorCount, "errors"); this .debug("\t", this ._failureCount, "failures"); //--------------------------------------------------------------------------- // 定义 request 对象,把需要写入 build 的信息传递给 server 端 var request = { //url 为用于接收参数的 rest excutor url: "http://localhost/resultService", handleAs: "text", preventCache: true , content : // 总 test case 数量 "testCount: " + this ._testCount + "\n" + // 总 test suit 数量 "groupCount: " + this ._groupCount + "\n" + // 出错数量 "errorCount: " + this ._errorCount + "\n" + // 失败数量 "failureCount: " + this ._failureCount + "\n" + // 全部执行过程中的 log 内容 "logBody: " + dojo.byId("logBody").innerHTML + // 执行结果是成功或者失败,将被 Ant build 用于决定是否让 build 失败 this ._errorCount + this ._failureCount > 0 ? "successful" : "failed", load: function (data, ioargs){ console.log("ok"); }, error: function (error){ console.log("error"); } }; // 向 server 端发送 POST 请求 dojo.xhrPost(request); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import java.io.IOException; import java.io.InputStream; import java.net.URL; public class ResultRequest { public static void main(String[] args) throws IOException { URL u = new URL("http://localhost/resultService"); //int tryCounts = 0; while (true ){ //if(tryCounts > 60) System.exit(1); //tryCounts++; InputStream inStream = u.openStream(); String result = readContentFromStream(inStream); if (result != null && !result.trim().equals("")) { System.out.println(result); if (result.endsWith("failed")) System.exit(1); else return ; } else { Thread.sleep(1000); } } } } |
1 2 3 | <target name="testResult" depends="runUT"> <java classname="ResultRequest" classpath="lib" failonerror=”true”/> </target> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |