1
我在Soapui有一個項目和一個運行項目所有測試的groovy代碼。 結果可以在輸出控制檯中看到。 所以我想要的是保存輸出ina文件的內容。Groovy如何將控制檯輸出保存到文件?
在Java中,我們可以這樣做:
//create a buffered reader that connects to the console, we use it so we can read lines
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//read a line from the console
String lineFromInput = in.readLine();
//create an print writer for writing to a file
PrintWriter out = new PrintWriter(new FileWriter("c:/temp7/output.txt"));
//output to the file a line
out.println(lineFromInput);
//close the file
out.close();
是否有一個等效代碼在Groovy? 謝謝您
我相信你會從soapui工具運行該項目。對?但是爲了收集輸出,你在哪裏運行上面的java代碼呢?順便說一句,相同的代碼應該也適用於常規。 – Rao 2015-01-26 18:06:22
我在所有測試結束時從groovy步驟運行此代碼。我嘗試了相同的代碼,但我有錯誤,它應該是這樣的def file = new File('c:/temp7/sample.txt') file.withWriter('UTF-8'){ it.writeLine '將此文字添加到文件中。' }在這裏,我應該添加控制檯輸出的內容。 – 2015-01-26 18:09:35
你的意思是說,該項目是從一個groovy步驟本身運行? – Rao 2015-01-26 18:12:43