您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > TestNG
TestNG控制case运行顺序
作者:网络转载 发布时间:[ 2015/9/30 14:15:48 ] 推荐标签:TestNG

  3.例如下代码
  package yycuser13.test.testcase;
  import org.testng.annotations.Test;
  import org.testng.annotations.Test;
  public class Test1{
  @Test(priority=3)
  public void login(){
  System.out.println("my name id login");
  }
  @Test(priority=2)
  public void login1(){
  System.out.println("my name id login1");
  }
  @Test(priority=1)
  public void logout(){
  System.out.println("my name id logout");
  }
  @Test(priority=4)
  public void logout1(){
  System.out.println("my name id logout1");
  }
  }
  运行结果为:
  my name id logout
  my name id login1
  my name id login
  my name id logout1
  ===============================================
  Suite
  Total tests run: 4, Failures: 0, Skips: 0
  4.例如下代码 加入了 dependsOnGroups
  package yycuser13.test.testcase;
  import org.testng.annotations.Test;
  public class Test1{
  @Test(groups={"login"},dependsOnGroups={"logout"})
  public void login(){
  System.out.println("my name id login");
  }
  @Test(groups={"login"},dependsOnGroups={"logout"})
  public void login1(){
  System.out.println("my name id login1");
  }
  @Test(groups={"logout"})
  public void logout(){
  System.out.println("my name id logout");
  }
  @Test(groups={"logout"})
  public void logout1(){
  System.out.println("my name id logout1");
  }
  }
  运行结果为:
  my name id logout
  my name id logout1
  my name id login
  my name id login1
  PASSED: logout
  PASSED: logout1
  PASSED: login
  PASSED: login1
  ===============================================
  Default test
  Tests run: 4, Failures: 0, Skips: 0
  5.例如下代码 使用dependsOnMethods
  package yycuser13.test.testcase;
  import org.testng.annotations.Test;
  public class Test1{
  @Test(dependsOnMethods={"login1"})
  public void login(){
  System.out.println("my name id login");
  }
  @Test(dependsOnMethods={"logout"})
  public void login1(){
  System.out.println("my name id login1");
  }
  @Test
  public void logout(){
  System.out.println("my name id logout");
  }
  @Test(dependsOnMethods={"login"})
  public void logout1(){
  System.out.println("my name id logout1");
  }
  }
  运行结果为:
  my name id logout
  my name id login1
  my name id login
  my name id logout1
  PASSED: logout
  PASSED: login1
  PASSED: login
  PASSED: logout1
  ===============================================
  Default test
  Tests run: 4, Failures: 0, Skips: 0

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd