测试前设置TestNG的输出目录
Set output directory of TestNG before test
我正在 运行使用 Eclipse 进行一些 TestNG 测试,使用 XML 文件(右键单击,运行 作为 TestNG 套件)。我仅将 maven 用于依赖项,而不用于 运行ning 测试。有没有办法在代码中设置输出目录?
例如
System.out.println(ctx.getOutputDirectory());
打印当前输出目录,默认为test-output。但为什么没有 setOutputDirectory?我想将 @BeforeTest 方法中的输出目录设置为我在 testng.xml 文件中设置的文件夹。
您有可用的 setOutputDirectory()
仅当您 运行 以编程方式测试时:
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
或者您可以将 ouputDirectory 作为命令行参数 -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";
找到答案。
@BeforeTest
public void setup(ITestContext ctx) {
TestRunner runner = (TestRunner) ctx;
runner.setOutputDirectory("/Path/To/Store/Output");
}
我正在 运行使用 Eclipse 进行一些 TestNG 测试,使用 XML 文件(右键单击,运行 作为 TestNG 套件)。我仅将 maven 用于依赖项,而不用于 运行ning 测试。有没有办法在代码中设置输出目录?
例如
System.out.println(ctx.getOutputDirectory());
打印当前输出目录,默认为test-output。但为什么没有 setOutputDirectory?我想将 @BeforeTest 方法中的输出目录设置为我在 testng.xml 文件中设置的文件夹。
您有可用的 setOutputDirectory() 仅当您 运行 以编程方式测试时:
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
或者您可以将 ouputDirectory 作为命令行参数 -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";
找到答案。
@BeforeTest
public void setup(ITestContext ctx) {
TestRunner runner = (TestRunner) ctx;
runner.setOutputDirectory("/Path/To/Store/Output");
}