Besides third-party libraries such as Convey and Ginkgo , with simple Golang 1.7 you can run tests sequentially. You can read more here.
func TestFoo(t *testing.T) { // <setup code> t.Run("A=1", func(t *testing.T) { ... }) t.Run("A=2", func(t *testing.T) { ... }) t.Run("B=1", func(t *testing.T) { ... }) // <tear-down code> }
And you can run them conditionally with
go test -run ''
So let's say you have the user package from the REST api that you want to check. You need to test the create handler to be able to test the login handler. Normally I would have this on user_test.go
type UserTests struct { Test *testing.T} func TestRunner(t *testing.T) { t.Run("A=create", func(t *testing.T) { test:= UserTests{Test: t} test.TestCreateRegularUser() test.TestCreateConfirmedUser() test.TestCreateMasterUser() test.TestCreateUserTwice() }) t.Run("A=login", func(t *testing.T) { test:= UserTests{Test: t} test.TestLoginRegularUser() test.TestLoginConfirmedUser() test.TestLoginMasterUser() }) }
Then I can add methods to the UserTest type that will not be executed by the go test command in any _test.go file
func (t *UserTests) TestCreateRegularUser() { registerRegularUser := util.TableTest{ Method: "POST", Path: "/iot/users", Status: http.StatusOK, Name: "registerRegularUser", Description: "register Regular User has to return 200", Body: SerializeUser(RegularUser), } response := util.SpinSingleTableTests(t.Test, registerRegularUser) util.LogIfVerbose(color.BgCyan, "IOT/USERS/TEST", response) }
CESCO
source share