355d19418b
- 修改 ApiCase 和 ApiResponse 结构,新增 Verify 方法以支持自定义校验函数 - 更新 Get、Post、Put、Delete 方法,允许使用 expect 参数进行更灵活的响应断言 - 添加 ExpectResult 方法,支持对响应结果的结构和类型进行后置校验 - 更新文档,详细说明新功能的使用方法和示例,提升测试框架的可用性 - 增强 Swagger 生成逻辑,支持输出新的 expect 和 verifyError 字段
45 lines
816 B
Go
45 lines
816 B
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
. "code.hoteas.com/golang/hotime"
|
|
)
|
|
|
|
var ProjectTest = ProjTest{
|
|
"test": TestTest,
|
|
"mysql": MysqlTest,
|
|
"dmdb": DmdbTest,
|
|
"cache": CacheTest,
|
|
"expect_demo": ExpectDemoTest,
|
|
}
|
|
|
|
var testApp *TestApp
|
|
|
|
func TestMain(m *testing.M) {
|
|
// Go test 的 CWD 是包目录 example/app/,切回 example/ 使相对路径正确
|
|
_ = os.Chdir("..")
|
|
|
|
testApp = NewTestApp("config/config.json",
|
|
TestProj{
|
|
"app": {
|
|
Proj: Project,
|
|
Tests: ProjectTest,
|
|
},
|
|
},
|
|
)
|
|
|
|
// 在测试前初始化各数据库的测试表和种子数据
|
|
SetupDatabase(&testApp.Db)
|
|
|
|
code := m.Run()
|
|
testApp.PrintCoverage()
|
|
testApp.GenerateSwagger("My API", "1.0.0", testApp.Config.GetString("tpt"))
|
|
os.Exit(code)
|
|
}
|
|
|
|
func TestApi(t *testing.T) {
|
|
testApp.RunTests(t)
|
|
}
|