将JUnit结果打印到文件

Erg*_*lat 5 java junit junit4

我想将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();
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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");       

}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过,p.append()但是没有用。请帮忙。

Mar*_*urg 1

您可能在这里重新发明轮子。 ANTMaven、X 构建工具或CI 服务器应该会为您完成此操作。