main_test.go 1.3 KB

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