zoukankan      html  css  js  c++  java
  • testNG安装与使用

    1、Eclipse集成TestNG插件

      a.下载TestNG离线插件并解压得到features和plugins两个文件夹;

      b.将features文件下的org.testng.eclipse_6.9.8.201510130443复制到D:eclipsefeatures目录下;

      c.将plugins文件下的org.testng.eclipse_6.9.8.201510130443复制到D:eclipseplugins目录下;

      注:重启Eclipse,windows=》preferences=》TestNG

    2、导入testNG依赖包

      a.进入maven中央仓库地址:https://mvnrepository.com/

      

      b.Maven项目下的pom.xml配置    

      <dependencies>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
           <groupId>org.testng</groupId>
           <artifactId>testng</artifactId>
           <version>6.9.10</version>
           <scope>test</scope>
        </dependency>
      </dependencies>

    3.配置完成,新建TestNGDemo01类

      

    4.为了方便访问,也可以将testng.xml 拖动至项目根目录下:

    5.运行套件执行类可以在这么配置

     

     6.TestNGDemo01示例代码

    package cn.xiaobing.testng;
    
    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeSuite;
    import org.testng.annotations.AfterSuite;
    
    public class TestNGDemo01 {
      @Test(dataProvider = "dp")
      public void f(Integer n, String s) {
    	  System.out.println("TestNGDemo01.f()");
      }
      @BeforeMethod
      public void beforeMethod() {
    	  System.out.println("TestNGDemo01.beforeMethod()");
      }
    
      @AfterMethod
      public void afterMethod() {
    	  System.out.println("TestNGDemo01.afterMethod()");
      }
    
    
      @DataProvider
      public Object[][] dp() {
    	  System.out.println("数据提供者:@DataProvider");
        return new Object[][] {
          new Object[] { 1, "a" },
          new Object[] { 2, "b" },
        };
      }
      @BeforeClass
      public void beforeClass() {
    	  System.out.println("TestNGDemo01.beforeClass()");
      }
    
      @AfterClass
      public void afterClass() {
    	  System.out.println("TestNGDemo01.afterClass()");
      }
    
      @BeforeTest
      public void beforeTest() {
    	  System.out.println("TestNGDemo01.beforeTest()");
      }
    
      @AfterTest
      public void afterTest() {
    	  System.out.println("TestNGDemo01.afterTest()");
      }
    
      @BeforeSuite
      public void beforeSuite() {
    	  System.out.println("TestNGDemo01.beforeSuite()");
      }
    
      @AfterSuite
      public void afterSuite() {
    	  System.out.println("TestNGDemo01.afterSuite()");
      }
    
    }
    

    7.执行套件:

    8.输出结果:

     总结:亲测后总结,分享给需要的人,不足之处后续修正补充!

  • 相关阅读:
    Python模拟浏览器前进后退操作
    Python之sort()函数详解
    Python之抓取网页元素
    Python之列表与元组的区别详解
    Python3之正则表达式详解
    Python解析JSON详解
    Python3之文件读写操作详解
    Python之import方法引入模块详解
    2015年12月英语四级写作模板
    裸考大学英语四级写作核心词汇及模板
  • 原文地址:https://www.cnblogs.com/xiaozhaoboke/p/10865016.html
Copyright © 2011-2022 走看看