2016-06-28 4 views
0

난 그냥 매개 변수 테스트를 추출 할 때 올바르게 통과한다 내가 매개 변수를 조작하려고하면 RunTimeException이 잘못되었다! 무엇이 잘못되었는지 이해하는 데 도움이됩니다!testNG @BeforeMethod는 호수 매개 변수 ITestResult를 매개 변수와 함께 사용합니다.

@BeforeMethod 
    public void beforeMethodBlock(ITestResult result){ 
     ReportGenerator.add(result.getParameters());  
    } 
public class ReportGenerator { 
    private static Object[][] testData= new Object[50][2]; 
    private static Integer index; 
    public static void add(Object[] data){ 
     testData[index++]=data; 

    } 
} 
+1

당신이 예외의 전체 스택 트레이스를 공유 할 수 있을까요? – juherr

+0

방금 ​​추가 메서드에서 매개 변수를 인쇄하면 프로그램이 실패합니다! – Artur

+0

java.lang.RuntimeException – Artur

답변

0

그것은 당신의 index 변수가 초기화되지 않습니다 보이는 대신 intInteger를 사용할 때 (왜?!) 기본값은 null입니다.

int을 사용하여 초기화하십시오.

TestNG의에서 BeforeMethod이 ITestContext의 매개 변수를 가질 수
+0

문제가 int에 없습니다. 그냥 인쇄 ("+ 데이터 [0])하면 오류가 발생합니다. BeforeMethod 주석과 수신기에서 클래스에 몇 가지 문구를 쓸 수 없다는 인상을 받았습니다! libs – Artur

+0

소스 코드에 따르면 테스트 결과에는 상태가 없으며 발생하지 않아야합니다. 6.9.12의 testng을 사용하고 있다면, github에서 문제를 열 ​​수 있습니까? 정수 대신 – juherr

+0

int가 작동합니다! 하지만 만약 내가 System.out.println ("+ 데이터 [0]) 쓰기; 잘못되다. – Artur

0
  • 다음에 수행 할 수있는 실행되는 TestMethod의 이름을 얻을 수있는 경우 방법은 ItestResult

의 매개 변수를 가질 수 있습니다 후 메서드 (java.lang.reflect.Method) 개체입니다.

@BeforeMethod public void beforeMethod(Method m) { System.out.println(m.getName()); }
또는
@BeforeMethod public void beforeMethod(ItestContext testContext) { // Do testContext related processing }

참조 : -
How do I get the name of the test method that was run in a testng tear down method?

관련 문제