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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

X-Mas Musings –在Grails集成测试中不要使用随机服务器端口

發布時間:2023/12/3 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 X-Mas Musings –在Grails集成测试中不要使用随机服务器端口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對許多人來說,十二月是反思或思考的時期。 所以我決定在去年的事情和想法,以反映- 每一天 ,直到圣誕節。 這是第四天

對于Grails集成測試,了解應用程序當前在哪個端口上運行非常有用。

Spring Boot以及因此建立在它上面的Grails都通過一個名為local.server.port的屬性公開了啟動時隨機選擇的端口。

當專門針對Grails進行谷歌搜索時,通常會出現在mrhaki的Grails善意:集成測試頁面中使用隨機服務器端口 -Grails善意的極好來源-該書清楚地顯示了如何使用@Value來獲取local.server.port屬性的值。 。

在我自己的示例中,您可以在下面看到它的運行情況。

import grails.plugins.rest.client.RestBuilder import grails.plugins.rest.client.RestResponse import grails.test.mixin.integration.Integration import org.springframework.beans.factory.annotation.Value import spock.lang.Specification@Integration class SomeIntegrationSpec extends Specification {@Value('${local.server.port}')Integer serverPortvoid "health check works"() {when:String url = "http://localhost:${serverPort}/example/health"def response = new RestBuilder().get(url)then:response.status == 200} }

去年某個時候,我意識到:我根本不需要。

@Integration class SomeIntegrationSpec extends Specification {// no serverPort!void "health check works"() {when:String url = "http://localhost:${serverPort}/example/health"def response = new RestBuilder().get(url)then:response.status == 200} }

WAT? 沒有serverPort屬性-您仍在"http://localhost:${serverPort}/example/health"嗎?

Jip,至少在Grails 3.3.0中具有此功能,即使用corrct值初始化的確切屬性Integer serverPort ,是通過@Integration批注直接添加到測試類的 -特別是:其AST轉換幫助器類。

正如英國小說作家亞瑟·克拉克 ( Arthur C. Clarke)所說:

任何足夠高級的注釋都無法與魔術區分開。

如此真實。

翻譯自: https://www.javacodegeeks.com/2017/12/x-mas-musings-not-use-random-server-port-grails-integration-tests.html

總結

以上是生活随笔為你收集整理的X-Mas Musings –在Grails集成测试中不要使用随机服务器端口的全部內容,希望文章能夠幫你解決所遇到的問題。

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