gpt4 book ai didi

java - 将 JUnit 结果打印到文件

转载 作者:搜寻专家 更新时间:2023-10-31 20:23:45 29 4
gpt4 key购买 nike

我想将 JUnit 测试的结果打印到 .txt 文件中。

以下是我的代码:

try {
//Creates html header
String breaks = "<html><center><p><h2>"+"Test Started on: "+df.format(date)+"</h2></p></center>";

//Creating two files for passing and failing a test
File pass = new File("Result_Passed-"+df.format(date)+ ".HTML");
File failed = new File("Result_Failed-"+df.format(date)+ ".HTML");
OutputStream fstreamF = new FileOutputStream(failed, true);
OutputStream fstream = new FileOutputStream(pass, true);
PrintStream p = new PrintStream(fstream);
PrintStream f= new PrintStream(fstreamF);

//appending the html code to the two files
p.append(breaks);
f.append(breaks);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

以下是我的示例测试用例:

public void test_001_AccountWorld1() {

// Open the MS CRM form to be tested.
driver.get(crmServerUrl + "account");
nameOfIFRAME = "IFRAME_CapCRM";

PerformCRM_World1("address1_name", "address1_name", "address1_line1", "address1_postalcode", true);

assertEquals(firstLineFromForm.toString(), "");
assertEquals(secondLineFromForm.toString(), "Donaustadtstrasse Bürohaus 1/2 . St");
assertEquals(postcodeFromForm.toString(), "1220");

}

我试过 p.append() 但没有用。请帮忙。

最佳答案

通常,您可以将输出重定向到文件,如下所示:
- 如果您使用的是 eclipse :运行配置-->Commons-->OutputFile-->你的文件名 enter image description here

  • 如果您从命令行运行,只需使用:java ..... >output.txt

关于java - 将 JUnit 结果打印到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4398323/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com