main_test.go 1.6 KB

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