在TestNG中捕获控制台输出?

在TestNG中捕获控制台输出?,testng,gradle,Testng,Gradle,我在gradle中使用TestNG+Reporting per wiki(我固定在cookbook上,因为默认示例对我不起作用) 我想以某种方式在TestNG中捕获控制台输出。这可能吗 多谢各位 Misha好的,我仍然不知道如何正式执行此操作,但我只是重定向了标准输出和错误: /** * Redirect standard output and error to appropriate files */ public void redirectStandardOutputAndErrorTo

我在gradle中使用TestNG+Reporting per wiki(我固定在cookbook上,因为默认示例对我不起作用)

我想以某种方式在TestNG中捕获控制台输出。这可能吗

多谢各位
Misha

好的,我仍然不知道如何正式执行此操作,但我只是重定向了标准输出和错误:

/**
 * 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)
}