1、創建一個Maven工程:之前的文章有詳細創建過程,這里就不詳細介紹了
2、導入TestNG依賴包:打開pom.xml文件,添加以下內容,然后install一下(也可以根據之前的文章去尋找版本更高的testng)
<!-- testNG-自動化測試框架 --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.14.3</version> <scope>test</scope> </dependency> <!-- testNG-end -->
3、安裝TestNG插件(IntelliJ IDEA-Preferences-Plugins)
輸入testng,點擊install(我之前已經裝過了,所以是Installed)
4、添加testng.xml文件:點擊項目名,選擇Creat TestNG XML(如果沒有看到 Creat TestNG XML 這個選項,可以重啟idea,如果還沒有,重復第3步重新安裝testng插件,多嘗試幾次)
添加成功后,也需要重啟idea,才能看到testng.xml文件
5、添加測試類:選擇一個需要測試的類,選中類名點擊 option+enter 選擇 Create Test
Testing library選中TestNG,選擇需要的選項,點擊ok(可能會提示“TestNG library not found In the module”,是因為沒有在pom.xml文件中,寫入TestNG插件的依賴,點擊下圖的“Fix”按鈕,即可自動添加)
創建成功