TestNG实战:IDEA 创建TestNG test


TestNG 是自动化测试框架,比Junit更强大,可用于单元测试,功能测试,端到端测试等,下面我们就介绍一下如何基于IntelliJ IDEA 创建TestNG test

1. 打开IntelliJ IDEA -> Create New Project -> Next ->  Next -> 编写项目名称 -> Finished

 2. 打开https://mvnrepository.com/artifact/org.testng/testng/7.0.0 下载testng-7.0.0.jar 文件,放到项目文件夹中。

 

 

 3. File -> Project Structure... -> Modules -> Dependencies -> Add JARs or directories 添加testng-7.0.0.jar -> Apply -> OK

 

 

 4. 创建测试用例

package com.testng.demo;

import org.testng.Assert;
import org.testng.annotations.Test;

public class Test1 {
    @Test
    public void case1(){
        Assert.assertEquals(1,1);
    }
    @Test
    public void case2(){
        Assert.assertEquals("hello","hello");;
    }
}

5.  Add Configuration... -> Add New Configuration -> TestNG

 

 

 6. 自定义名称 Testng -> 选择测试类 如Test1 -> OK 

 

 

 7. Listeners -> Use default reporters -> Apply -> OK

 

 

8. 运行Testng

 

 

 问题:报错

Exception in thread "main"

java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException

 

 

 

解决方法:

缺少jcommander的jar包导致,按照步骤2下载jcommander,加入到依赖中即可。

下载地址如下:

https://mvnrepository.com/artifact/com.beust/jcommander/1.81

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM