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