2017-11-22 1 views
0

프로그래밍 방식으로 모든 테스트 케이스를 영원히 실행하는 방법은 무엇입니까? 아래는 내가 가진 설정입니다 ... 이제이 코드를 무한히 실행해야합니다 ... 또 다른 요구 사항은 @ aftersuite 이후에 앱을 다시 시작해야한다는 것입니다 ... 각 후속 작업 후에 보고서를 생성해야하기 때문에 테스트 케이스를 분해해야합니다 ...프로그래밍 방식으로 모든 테스트 케이스를 영원히 실행하는 방법은 무엇입니까?

예를 들어

:

public class SimpleTest extends TestBase 
{ 
    AppiumDriver driver; 

    @BeforeSuite 
    public void setUp() throws MalformedURLException { 

     // DesiredCapabilities and all setup 
    } 
    @Test(priority = 1) 
    public void testcase1()throws InterruptedException { 
     login(); 
    } 

    @Test(priority = 2) 
    public void testcase2() throws InterruptedException { 
     //something 
    } 

    @Test(priority = 3) 
    public void testcase3() throws InterruptedException { 
     //something 
    } 

    @Test(priority = 4) 
    public void testcase4 throws InterruptedException { 
    //something 
    } 

    @Test(priority = 5) 
    public void testcase() throws InterruptedException{ 
     //something 
    } 

    @Test(priority = 6) 
    public void testcase6() throws InterruptedException{ 
    //something 
    } 

    @Test(priority = 7) 
    public void testcase_logout() throws InterruptedException { 
     logout(); 
    } 

    @AfterSuite 
    public void testCaseTearDown() 
    { 
     driver.quit(); 
    } 
} 
+1

... 무한 루프를 사용 하시겠습니까? – Dabiuteef

+0

코드로 제안 해 주실 수 있습니까? 위의 설정은 내 설정입니다. –

+0

무한 루프에서 testng 클래스의 run() 메서드를 호출합니다. doc의 예제를 참조하십시오. - http://testng.org/doc/documentation-main.html#running-testng-programmatically – Grasshopper

답변

0

테스트를 부를 것이다 또 다른 클래스를 만듭니다 ...

public SimpleTest { 
    public static void main(String[] args) { 
     while (true) { 
      org.junit.runner.JUnitCore.main("SimpleTest"); 
     } 
    } 
} 
+0

죄송합니다.이 작업을 수행하지 않습니다 ... ... ( –

+0

코드에 JUnitCore가있는 행 테스트를 호출합니다. 예제 에서처럼 메인에 넣을 수도 있고 @Before 태그가있는 메소드 내부에 루프 안에 넣을 수도 있습니다. 그러면 가장 먼저 호출되거나 호출 될 필요가있는 곳에서 호출됩니다. – clinomaniac

+0

내가 무슨 뜻인지 모르겠어. 어떻게 이걸 @BeforeSuite 메서드에서 사용할 수 있을까? –

0

는 testNG.xml에서 테스트를 정렬합니다.

<?xml version="1.0" encoding="UTF-8"?> 
<suite name="Regression suite" verbose="1" > 
    <test name="SampleTests" > 
    <classes> 
     <class name="com.first.example.SampleTest"/> 
    </classes> 
</test> 
</suite> 

그런 다음 프로그래밍 방식으로 TestNG 개체를 실행하십시오.

import org.testng.TestNG; 

import java.util.List; 

public class RunTestNGXML { 

    public static void main(String[] args) { 
     TestNG testng = new TestNG(); 
     List<String> suites = Lists.newArrayList(); 
     suites.add("testng.xml"); 
     testng.setTestSuites(suites); 
     String outputDir ="src"+File.separator+"reports"; 
     Calendar calendar = Calendar.getInstance(); 
     SimpleDateFormat formatter = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss"); 

     while(true){ 
     testng.setOutputDirectory(outputDir+File.separator+formater.format(calendar.getTime())); 
     testng.run(); 
     } 
    } 
} 

무한 루프에주의해야 할 점은 이메일로 전송할 수-보고서는 각 반복에 덮어 쓸 것입니다. 따라서 테스트 출력 디렉토리 경로를 타임 스탬프로 구성하십시오. 그렇지 않으면 log4j appender가 연속 로깅 작업을 쉽게 수행 할 수 있습니다.

관련 문제