2015-01-19 2 views
2

Eclipse에서 TestNG 테스트를 실행하고 있습니다 (XML 파일을 사용하여 마우스 오른쪽 단추를 클릭하고 TestNG 제품군으로 실행). 필자는 테스트를 실행하지 않고 종속성에만 maven을 사용합니다. 코드에서 출력 디렉토리를 설정하는 방법이 있습니까? 예를테스트 전에 TestNG의 출력 디렉터리를 설정하십시오.

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

를 들어

은 기본적으로 테스트 출력 전류 출력 디렉토리를 인쇄합니다. 하지만 setOutputDirectory가없는 이유는 무엇입니까? @BeforeTest 메서드의 출력 디렉터리를 testng.xml 파일에서 설정 한 폴더로 설정하고 싶습니다.

답변

3

는 답을 발견.

@BeforeTest 
public void setup(ITestContext ctx) { 
    TestRunner runner = (TestRunner) ctx; 
    runner.setOutputDirectory("/Path/To/Store/Output"); 
} 
+0

그게 좋습니다! 당신의 TestRunner에 대한 설명서를 찾을 위치를 말해 줄 수 : 나는 질문의 몇 http://testng.org/doc/documentation-main.html#dependency-injection –

+0

@Student TestNG의 방법에서 개체 분사 메커니즘에 대해 잊어 버렸습니다. setOutputDirectory? 그리고 이전 메서드에 전달 된 ITestContext 개체가 TestRunner 개체가 될 것이라는 것을 어떻게 알 수 있습니까? –

7

당신은이 setOutputDirectory()을 사용할 수 당신은 프로그래밍 방식 TestNG를 실행하는 경우에만 :

http://testng.org/doc/documentation-main.html#running-testng

을 -d

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 전달할 수를 이클립스는 기본 디렉토리를 갖는다 :

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"; 
+0

나는 실제로 나 자신도 대답을 발견했다. 나는 그것을 시험했으며 작동한다. – Student

관련 문제