TestNG+Maven+IDEA环境搭建
TestNG+Maven+IDEA環(huán)境搭建
前言:
主要進行TestNG測試環(huán)境的搭建?
所需環(huán)境:?
1、IDEA UItimate?
2、JDK?
3、Maven
一、創(chuàng)建工程?
File –>new –>Project–>next–>finish
上面兩項名稱自己定義
最后工程目錄?
二、導入相關依賴包和插件
1)添加testng依賴包?
在pom.xml文件添加
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
2)添加編譯插件和執(zhí)行測試插件
<build><plugins><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <compilerArgs> <arg>-Xlint:unchecked</arg> <arg>-Xlint:deprecation </arg> <!--<arg>endorseddirs=${endorsed.dir}</arg>--> </compilerArgs> </configuration> </plugin> 添加插件 關聯(lián)testNg.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> <configuration> <testFailureIgnore>true</testFailureIgnore> <suiteXmlFiles> <file>res/testNG.xml</file> </suiteXmlFiles> <!--<workingDirectory>target/</workingDirectory>--> </configuration> </plugin> </plugins> </build>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
具體的maven插件請查看
http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin/?
http://www.infoq.com/cn/news/2011/05/xxb-maven-8-plugin
三、創(chuàng)建測試類?
在新建測試類,代碼如下
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
IDEA執(zhí)行編譯
編譯情況
四、編寫testNG.xml
創(chuàng)建一個新的文件夾 res,里面創(chuàng)建testNG.xml (該文件名自己可以定義,相應需要在pom.xml的文件修改對應文件名)?
編寫testNG.xml
?
?
差不多搞定了,我們來看下使用maven執(zhí)行測試
在IDEA控制臺Terminal輸入
mvn -f pom.xml clean test -DxmlFileName=testNG.xml編譯結果
測試報告
target/surefire-reports/com.testproj.Demo.TestDemo1文件夾下打開報告?
到此創(chuàng)建TestNG+Maven+IDEA環(huán)境完成。
轉載于:https://www.cnblogs.com/ceshi2016/p/6512235.html
總結
以上是生活随笔為你收集整理的TestNG+Maven+IDEA环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: v盾密码是什么
- 下一篇: 做社区团购的大忌 这几点一定要注意