zoukankan      html  css  js  c++  java
  • TestNG+Maven+IDEA 环境配置+入门

    一、环境配置

    1、安装IDEA(参考:https://blog.csdn.net/m0_38075425/article/details/80883078

    2、在Prefernces,通过Plugins插件安装TestNG-J(新版IDEA会自动集成插件)

    3、测试项目中,导入jar包(添加依赖)

    两种方式

    1、直接在pom.xml中引入下面代码,IDEA会自动下载依赖包

     <dependencies>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.10</version>  //版本号可以根据需要修改
                <scope>compile</scope>
            </dependency>
     </dependencies>

    2、在Project Structure中,点击+,选择maven项目,搜索TestNG,导入jar包(这个方法搜索比较慢。。。)

    (可参考 https://blog.csdn.net/u010270891/article/details/82978260

    二、编写代码

    TestNG基本用法参考:https://blog.csdn.net/duanlei123456/article/details/87454737

    可以直接引用TestNG注解,以下是我的测试demo

    package com.cat;
    
    import org.testng.Assert;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    public class Test01 {
    
        @BeforeClass
        public void beforeClass(){
            System.out.println("beforeClase");
        }
    
        @AfterClass
        public void afterClass(){
            System.out.println("afterClass");
        }
    
        @Test
        public void testcase1(){
            Assert.assertEquals(1,1);
            System.out.println("test01");
        }
    
        @Test
        public void testcase2(){
            Assert.assertTrue(true);
            System.out.println("test02");
        }
    
        @DataProvider(name="user")
        public Object[][] getStr(){
            return new Object[][]{
                    {"","","账户不能为空"},
                    {"admin","","密码不能为空"},
                    {"admin","123","密码错误"}
            };
        }
    
        @Test(dataProvider = "user")
        private void sout(String uname,String pword,String msg){
            System.out.println(uname+"->"+pword+"->"+msg);
        }
    
    }
    

      

  • 相关阅读:
    ICMP协议
    观察者模式-Observer
    模板方法模式-Template Method
    Java的演变过程
    汉诺塔-Hanoi
    外观模式-Facade
    JDK5-增强for循环
    JDK5-可变参数
    动态代理与AOP
    代理模式-Proxy
  • 原文地址:https://www.cnblogs.com/fatCat1/p/11330067.html
Copyright © 2011-2022 走看看