Stacked Q&A

testNG priorities & dependencies
  • 1 voting
  • 2022-05-25 00:00

    I'm having some issues with the priorities & dependencies on testNG. For example if I have this

    @Test
    public void login () { ... }
    
    @Test (dependsOnMethods = {"login"})
    public void method1 () { ... }
    
    @Test (dependsOnMethods = {"method1"})
    public void method2 () { ... }
    
    @Test (dependsOnMethods = {"login"})
    public void logout () { ... }
    

    In this case it run like this :

    login --> method1 --> logout --> method2

    and this won't work since i'm not connected anymore

    You gonna say to me just say that logout depends on method2 and everything will work ...

    Yes it will ... but when method1 or 2 will fail it will skip logout instead of doing it ... and that's not what I want.

    Then you gonna say me ... in that case it's easy just run with priorities instead of dependencies .... yeah but what if method1 fail ... then method2 might be good but won't work since method1 fail so I will have a false negative.

    Any idea on how to do it right ?

  • 1 908 0 0
첨부 파일
답변
총 1개의 답변이있습니다.
  • 답변일: 2022-05-25 00:00

    May be this can help

    @Test (priority=1)
    public void login()
    {   
        System.out.println("login");
    }
    
    @Test(priority=2,dependsOnMethods={"login"})
    public void method1()
    {
    
        System.out.println("method1");
    }
    
    @Test(priority=3,dependsOnMethods={"method1"})
    public void method2()
    {
    
        System.out.println("method2");
    }
    
    @Test(priority=4,dependsOnMethods={"login"})
    public void logout()
    {
    
        System.out.println("logout");
    }
    
  • 0 0 퍼블 채택!
Tages
    활동순위
    유저
      파트너사