1. 在idea中新建一個maven項目
2. 在pom.xml中添加testng和reportng依賴
<dependencies> <!-- 添加testNG依賴 --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.11</version> <scope>test</scope> </dependency> <!-- 添加reportNG依賴 --> <dependency> <groupId>org.uncommons</groupId> <artifactId>reportng</artifactId> <version>1.1.2</version> <scope>test</scope> <!-- 排除testNG依賴 --> <exclusions> <exclusion> <groupId>org.testng</groupId> <artifactId>testng</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
3. 安裝 Create TestNG XML插件(安裝該插件可以右擊項目自動生成testng.xml)
兩種方法:
A. https://plugins.jetbrains.com/plugin/9556-create-testng-xml下載插件到本地
在idea-File-Settings... 依次安裝兩個jar包

安裝dom4j-1.6.1.jar時會報錯,可能是版本不兼容的原因,暫未找到解決辦法

B. 在線安裝該插件

4. 安裝好后要求重啟idea,重啟好之后,右擊項目,選擇Create TestNG XML

新建成功后,在項目根目錄下生成testng.xml

