美文网首页
testng中provider+factory数据驱动

testng中provider+factory数据驱动

作者: 寻叶亭 | 来源:发表于2018-08-01 20:55 被阅读45次

    1.新建一个factory

    public class TestFactory {
      @DataProvider(name="userpass")
      public Object[][] userdata() {
          return new Object[][]{{"zhangsan","123456"},{"lisi","111111"}};
      }
      @Factory(dataProvider="userpass")
      public Object[] TestFactory(String username,String userid) {
          return new Object[]{new UserTest(username,userid)};
      }
    }
    

    2.创建usertest的class

      public  UserTest(String username,String userid) {
          this.username = username;
          this.userid = userid;
      }
      @Test
      public void login(){
          System.out.println("login with username = "+username+"and userid = "+userid);
      }
      @Test
      public void publish(){
          System.out.println("publish with username = "+username+"and userid = "+userid);
      }
    }
    

    3.执行结果,这样可保证多用户执行用例时数据不错乱

    结果

    相关文章

      网友评论

          本文标题:testng中provider+factory数据驱动

          本文链接:https://www.haomeiwen.com/subject/afxkvftx.html