2010-06-12 53 views

回答

1

好吧,我仍然不知道如何正式做到這一點,但我只是重定向標準輸出和錯誤:

/** 
* Redirect standard output and error to appropriate files 
*/ 
public void redirectStandardOutputAndErrorToFiles(className) { 
    def outFile=new File(System.getProperty("java.io.tmpdir")+File.separator+className+".out.log") 
    if (outFile.exists()) { 
    outFile.delete() 
    } 
    def errFile=new File(System.getProperty("java.io.tmpdir")+File.separator+className+".err.log") 
    if (errFile.exists()) { 
    errFile.delete() 
    } 
    def out=new PrintStream(new FileOutputStream(outFile)) 
    def err=new PrintStream(new FileOutputStream(errFile)) 
    System.setOut(out) 
    System.setErr(err) 
} 
0

您可以將以下指令添加到測試任務它告訴輸出標準流:

build.gradle:

test { 
    testLogging.showStandardStreams = true 
}