CI tests
Framework provides two external testing apis, one is a black box testing, one is the user's browser integration testing (depend on the chromedriver)
1
package main
2
3
import (
4
"github.com/GoAdminGroup/demo/tables"
5
"github.com/GoAdminGroup/go-admin/modules/config"
6
"github.com/GoAdminGroup/go-admin/tests"
7
"github.com/GoAdminGroup/go-admin/tests/common"
8
"github.com/GoAdminGroup/go-admin/tests/frameworks/gin"
9
"github.com/GoAdminGroup/go-admin/tests/web"
10
"github.com/gavv/httpexpect"
11
"net/http"
12
"testing"
13
)
14
15
// Black box testing
16
func TestDemoBlackBox(t *testing.T) {
17
tests.BlackBoxTestSuit(t, gin.NewHandler, config.DatabaseList{
18
"default": config.Database{
19
Host: "127.0.0.1",
20
Port: "3306",
21
User: "root",
22
Pwd: "root",
23
Name: "go_admin_demo_test", // WARNING: test database name must contains "test"
24
Driver: "mysql",
25
},
26
}, tables.Generators, func(cfg config.DatabaseList) {
27
// Data cleaner of the framework
28
tests.Cleaner(cfg)
29
// Clean your own data:
30
// ...
31
}, func(e *httpexpect.Expect) {
32
// Test cases of the framework
33
common.Test(e)
34
// Write your own API test, for example:
35
// More usages: https://github.com/gavv/httpexpect
36
e.POST("/signin").Expect().Status(http.StatusOK)
37
})
38
}
39
40
// User acceptance testing
41
func TestDemoUserAcceptance(t *testing.T) {
42
web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) {
43
// Write test case base on chromedriver, for example:
44
// More usages: https://github.com/sclevine/agouti
45
page.NavigateTo("http://127.0.0.1:9033/admin")
46
page.Contain("username")
47
page.Click("")
48
}, func(quit chan struct{}) {
49
// start the server:
50
// ....
51
}, true) // if local parameter is true, it will not be headless, and window not close when finishing tests.
52
}
Copied!
Last modified 1yr ago
Copy link