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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

用于混合Spock 1.x和JUnit 5测试的Maven项目设置

發布時間:2023/12/3 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用于混合Spock 1.x和JUnit 5测试的Maven项目设置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我為Maven創建了一個示例Groovy項目,該項目在一個項目中混合了Spock測試和JUnit 5測試。 在下一節中,我將描述如何設置這種Maven項目。

在項目中啟用Groovy

首先,您必須在項目中啟用Groovy。 一種可能性是將GMavenPlus插件添加到您的項目中。

< build > < plugins > < plugin > < groupId >org.codehaus.gmavenplus</ groupId > < artifactId >gmavenplus-plugin</ artifactId > < version >1.6.2</ version > < executions > < execution > < goals > < goal >addSources</ goal > < goal >addTestSources</ goal > < goal >compile</ goal > < goal >compileTests</ goal > </ goals > </ execution > </ executions > </ plugin > </ plugins > </ build >

目標addSources和addTestSources將Groovy(測試)源添加到Maven的主要(測試)源。 默認位置是src / main / groovy (對于主源)和src / test / groovy (對于測試源)。 目標編譯和compileTests編譯Groovy(測試)代碼。 如果您沒有Groovy主代碼,則可以省略addSource和compile 。

上面的配置始終使用最新發布的Groovy版本。 如果要確保使用特定的Groovy版本,則必須將特定的Groovy依賴項添加到類路徑中。

< dependencies > < dependency > < groupId >org.codehaus.groovy</ groupId > < artifactId >groovy</ artifactId > < version >2.5.6</ version > </ dependency > </ dependencies >

在項目中啟用JUnit 5

在項目中使用JUnit 5的最簡單設置是在測試類路徑中添加JUnit Jupiter依賴關系,并配置正確版本的Maven Surefire插件(至少為2.22.0版)。

< dependencies > <!--... maybe more dependencies --> < dependency > < groupId >org.junit.jupiter</ groupId > < artifactId >junit-jupiter</ artifactId > < scope >test</ scope > </ dependency > </ dependencies > < dependencyManagement > < dependencies > < dependency > < groupId >org.junit</ groupId > < artifactId >junit-bom</ artifactId > < version >${junit.jupiter.version}</ version > < scope >import</ scope > < type >pom</ type > </ dependency > </ dependencies > </ dependencyManagement > < build > < plugins > <!-- other plugins --> < plugin > < artifactId >maven-surefire-plugin</ artifactId > < version >2.22.1</ version > </ plugin > </ plugins > </ build >

在項目中啟用Spock

選擇正確的Spock依賴項取決于您在項目中使用的Groovy版本。 在我們的例子中,是Groovy 2.5版。 因此,我們在測試類路徑中需要版本1.x-groovy-2.5的Spock。

< dependencies > <!-- more dependencies --> < dependency > < groupId >org.spockframework</ groupId > < artifactId >spock-core</ artifactId > < version >1.3-groovy-2.5</ version > < scope >test</ scope > </ dependency > </ dependencies >

現在期望Spock測試和JUnit5測試在Maven構建中執行。 但是Maven只執行JUnit5測試。 所以發生了什么事?

我開始將Maven Surefire插件版本更改為2.21.0。 然后執行了Spock測試,但沒有執行JUnit5測試。 原因是,在Maven Surefire插件的2.22.0版本中,默認情況下,JUnit Platform Provider替換了JUnit4 provider。 但是版本1.x中的Spock基于JUnit4。 這將在Spock版本2中進行更改。此版本將基于JUnit5平臺。 因此,對于Spock 1.x,我們必須將JUnit Vintage依賴項添加到測試類路徑中。

< dependencies > <!-- more dependencies --> < dependency > <!--Only necessary for surefire to run spock tests during the maven build --> < groupId >org.junit.vintage</ groupId > < artifactId >junit-vintage-engine</ artifactId > < scope >test</ scope > </ dependency > </ dependencies >

這允許在JUnit平臺上運行較早的JUnit(3/4)測試。 使用此配置,Spock和JUnit 5測試都在Maven構建中執行。

鏈接

  • Groovy的示例Maven設置,包括Github上的JUnit 5和Spock
  • Maven GMaven Plus插件
  • Maven Surefire插件–使用JUnit 5平臺
  • JUnit 5用戶指南
  • Spock框架

翻譯自: https://www.javacodegeeks.com/2019/03/maven-project-setup-mixing-spock-junit-5-tests.html

總結

以上是生活随笔為你收集整理的用于混合Spock 1.x和JUnit 5测试的Maven项目设置的全部內容,希望文章能夠幫你解決所遇到的問題。

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