main_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. File: "./admin_test.db",
  18. Driver: "sqlite",
  19. Name: "goadmin_test",
  20. },
  21. }, tables.Generators, func(cfg config.DatabaseList) {
  22. // Data cleaner of the framework
  23. tests.Cleaner(cfg)
  24. // Clean your own data:
  25. // ...
  26. }, func(e *httpexpect.Expect) {
  27. // Test cases of the framework
  28. common.Test(e)
  29. // Write your own API test, for example:
  30. // More usages: https://github.com/gavv/httpexpect
  31. e.POST("/signin").Expect().Status(http.StatusOK)
  32. })
  33. }
  34. // User acceptance testing
  35. func TestDemoUserAcceptance(t *testing.T) {
  36. web.UserAcceptanceTestSuit(t, func(t *testing.T, page *web.Page) {
  37. // Write test case base on chromedriver, for example:
  38. // More usages: https://github.com/sclevine/agouti
  39. page.NavigateTo("http://127.0.0.1:9033/admin")
  40. //page.Contain("username")
  41. //page.Click("")
  42. }, func(quit chan struct{}) {
  43. // start the server:
  44. // ....
  45. }, true) // if local parameter is true, it will not be headless, and window not close when finishing tests.
  46. }