2017-04-13 1 views
-1

@beforeMethod 및 @AfterMethod를 그룹별로 설치 및 해체하고 싶습니다.TestNG @BeforeMethod 및 @AfterMethod 그룹 단위로 실행

나는 이런 식으로하려고했지만 항상 start()/end() 및 start2()/end2()를 실행합니다.

public class DemoTest 
{ 
    @BeforeMethod(groups = "1") 
    public void start() 
    { 
     System.out.println("Start"); 
    } 

    @Test(groups = "1") 
    public void test1() 
    { 
     System.out.println("test1"); 
    } 

    @Test(groups = "1") 
    public void test2() 
    { 
     System.out.println("test2"); 
    } 

    @AfterMethod(groups = "1") 
    public void end() 
    { 
     System.out.println("End"); 
    } 

    @BeforeMethod(groups = "2") 
    public void start2() 
    { 
     System.out.println("Start2"); 
    } 

    @Test(groups = "2") 
    public void test12() 
    { 
     System.out.println("test12"); 
    } 

    @Test(groups = "2") 
    public void test22() 
    { 
     System.out.println("test22"); 
    } 

    @AfterMethod(groups = "2") 
    public void end2() 
    { 
     System.out.println("End2"); 
    } 
} 

출력 :

Start 
Start2 
test1 
End 
End2 
Start 
Start2 
test12 
End 
End2 
Start 
Start2 
test2 
End 
End2 
Start 
Start2 
test22 
End 
End2 

내가이 출력이 원하는 :

Start 
test1 
End 
Start 
test2 
End 
Start2 
test12 
End2 
Start2 
test22 
End2 

내가 이것을 달성하는 방법을 확실하지 않다? 여기 도움이 필요해.

답변

1

"설정 및 해체를 위해 그룹당 @BeforeMethod@AfterMethod을 갖고 싶습니다."

원하는 것을 @BeforeGroups@AfterGroups이라고합니다. Further info.