日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

maven配置testng_TestNG和Maven配置指南

發布時間:2023/12/3 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 maven配置testng_TestNG和Maven配置指南 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

maven配置testng

為了有用,自動測試應該運行得非常快。 否則,將不會在開發期間經常運行,甚至在開發人員工作站上的默認配置中將被忽略。 最簡單的規則是只編寫小型單元測試,該測試將模擬給定類的鄰居。 然而,有時在IoC容器上下文(Spring,CDI,Guice)或使用嵌入式數據庫(H2,HyperSQL,Derby)中進行測試是有用的/必需的。 不幸的是,即使是這種類型的測試,也可能顯著增加總體測試執行時間。 我在一個項目中遇到這種情況,并且為了避免使用skipTests標志,我使用了TestNG和Maven Surefire插件中的組開發了一種解決方案。

測試分為三組:

  • 非常快速的真實單元測試(默認情況下全部為)–在開發過程中應經常運行(通過IDE或通過mvn測試,mvn軟件包)
  • 集成速度較慢,但??自給自足的測試(設置Spring上下文和/或使用嵌入式H2數據庫)–至少應在提交/推送之前或在給定部件上運行時運行(通過IDE或通過mvn集成測試,mvn安裝)
  • 真正的集成測試(需要訪問遠程服務器,例如測試Web服務或REST),應每天由CI服務器或從事集成工作的開發人員運行(mvn安裝,mvn集成測試并啟用其他配置文件)

為了實現給定的測試(或測試類),必須將其標記為“自集成”或“集成”(在方法或類級別):

@Test(groups = "self-integration") public void shouldInitializeChainedAppInfoProperly() {@Test(groups = "integration") public class FancyWebServiceIntegrationTest {

Maven Surefire插件應配置為從默認執行中排除“自集成”和“集成”測試組,并在“集成測試階段”添加“自集成”:

<build><plugins>(...)<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${ver.surefire-plugin}</version><executions><execution><id>default-test</id> <!-- to override default configuration - in fact: unit tests --><configuration><excludedGroups>self-integration,integration</excludedGroups></configuration></execution><execution><id>self-integration</id><phase>integration-test</phase><goals><goal>test</goal></goals><configuration><groups>self-integration</groups><reportsDirectory>target/self-integration-surefire-reports/</reportsDirectory></configuration></execution></executions></plugin></plugins></build>

另外(如果需要),可以創建在“集成測試”階段配置的帶有“集成”測試組的單獨的單獨配置文件。

<profiles>(...)<profile><id>integration</id><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${ver.surefire-plugin}</version><executions><execution><id>integration</id><phase>integration-test</phase><goals><goal>test</goal></goals><configuration><groups>integration</groups><reportsDirectory>target/integration-surefire-reports/</reportsDirectory></configuration></execution></executions></plugin></plugins></build></profile></profiles>

可以在AppInfo的人工分支(pom.xml和示例測試類)中找到工作示例。 根據您的需要很容易采用它。

所有三個測試組都有單獨的報告格式,以免彼此覆蓋。 作為擴展,可能可以將它們合并到一個匯總的測試報告中。

參考: 跑得快單元測試的時候,慢整合很少- TestNG的和Maven配置指南從我們JCG伙伴馬爾欽Zajaczkowski在固態軟博客。


翻譯自: https://www.javacodegeeks.com/2012/04/testng-and-maven-configuration-guide.html

maven配置testng

總結

以上是生活随笔為你收集整理的maven配置testng_TestNG和Maven配置指南的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。