大佬教程收集整理的这篇文章主要介绍了在 Gin Go 框架中测试,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我到处搜索有关如何解决此问题的信息。我没有完全覆盖在 Go 中测试 Gin GET 调用。
我正在调用测试,该函数的结果为 50%,但我似乎无法将结果提高到 100%。
Here is the code and the coverage output html
这是 Go 代码
var JsONGET = func(c *gin.Context) {
c.IndentedJsON(http.StatusOK,gin.H{
"code": http.StatusOK,"endpoint": c.request.requestuRI,"response": gin.H{
"body": "GET Response","type": "text",},"status": "http.StatusOK","type": "GET",})
}
// PingGET ...
func PingGET(c *gin.Context) gin.HandlerFunc {
return JsONGET
}
这是测试函数
func TestPingGET(t *tesTing.T) {
response := httptest.NewRecorder()
context,_ := gin.CreateTESTContext(responsE)
fmt.Println(response.CodE)
PingGET(context)
fmt.Println(response.CodE)
if response.Code != http.StatusOK {
t.Errorf("Error PingGET Failed")
}
}
这是输出的 HTML,但您需要查看图片以进一步了解哪些部分没有被测试。
package handler
import (
"net/http"
"github.com/gin-gonic/gin"
)
// JsONGET ...
var JsONGET = func(c *gin.Context) **{
c.IndentedJsON(http.StatusOK,gin.H{
"code": http.StatusOK,"response": gin.H{
"body": "GET Response",})
}**
// PingGET ...
func PingGET(c *gin.Context) gin.HandlerFunc {
return JsONGET
}
是否有人可以解释如何解决这个问题和/或解释这个问题?
可以在此处找到答案:GinDocs
以上是大佬教程为你收集整理的在 Gin Go 框架中测试全部内容,希望文章能够帮你解决在 Gin Go 框架中测试所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。