测试前设置TestNG的输出目录

我正在用eclipse运行一些testng测试,使用xml文件(右键单击,作为testng套件运行)。我只将maven用于依赖项,而不用于运行测试。有办法在代码中设置输出目录吗?
例如

System.out.println(ctx.getOutputDirectory());

打印当前输出目录,默认为测试输出。但是为什么没有setoutputdirectory呢?我想将@beforetest方法中的输出目录设置为testng.xml文件中设置的文件夹。


最佳答案:

您有setOutputDirectory()可用
只有在以编程方式运行testng时:

TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setOutputDirectory("your_directory_here")
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();

http://testng.org/doc/documentation-main.html#running-testng-programmatically
或者可以将outdirectory作为命令行参数-d传递
http://testng.org/doc/documentation-main.html#running-testng
eclipse采用默认目录:
public class TestNG {

/** The default name of the result's output directory (keep public, used by     Eclipse). */
public static final String DEFAULT_OUTPUTDIR = "test-output";