-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
47 lines (44 loc) · 1.29 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"./tables"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/tests"
"github.com/GoAdminGroup/go-admin/tests/common"
"github.com/GoAdminGroup/go-admin/tests/frameworks/gin"
"github.com/GoAdminGroup/go-admin/tests/web"
"github.com/gavv/httpexpect"
"log"
"testing"
)
// 黑盒测试
func TestMainBlackBox(t *testing.T) {
cfg := config.ReadFromJson("./config.json")
tests.BlackBoxTestSuit(t, gin.NewHandler, cfg.Databases, tables.Generators, func(cfg config.DatabaseList) {
// 框架自带数据清理
tests.Cleaner(cfg)
// 以下清理自己的数据:
// ...
}, func(e *httpexpect.Expect) {
// 框架自带内置表测试
common.Test(e)
// 以下写API测试:
// 更多用法:https://github.com/gavv/httpexpect
// ...
// e.POST("/signin").Expect().Status(http.StatusOK)
})
}
// 浏览器验收测试
func TestMainUserAcceptance(t *testing.T) {
web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) {
// 写浏览器测试,基于chromedriver
// 更多用法:https://github.com/sclevine/agouti
// page.NavigateTo("http://127.0.0.1:9033/admin")
// page.Contain("username")
// page.Click("")
}, func(quit chan struct{}) {
// 启动服务器
go startServer()
<-quit
log.Print("test quit")
}, true)
}