github.com/mailgun/holster/v4@v4.20.0/functional/README.md (about) 1 # Functional Test Framework 2 `go test`-like functional testing framework. 3 4 ## Why use `functional`? 5 `functional` is suggested when you want to rapidly develop code in the format 6 of a unit test or benchmark test using existing testing tools, but run it 7 outside of the `go test` environment. This is handy for use cases needing data 8 inspection and having low tolerance for errors. 9 10 `go test` doesn't support running tests programmatically from compiled code; it 11 requires the source code, which won't/shouldn't be available in production. 12 13 One such use case: runtime health check. An admin may remotely invoke a health 14 check job and watch it run. `functional` can manage the health check logic 15 once the RPC request is received. 16 17 Tools like Testify may be used for assertions and mocking. 18 19 ## Run Tests 20 ```go 21 import ( 22 "context" 23 "time" 24 25 "github.com/mailgun/holster/v4/functional" 26 ) 27 28 func main() { 29 ctx, cancel := context.WithTimeout(context.Background(), 10 * time.Minute) 30 defer cancel() 31 32 tests := []functional.TestFunc{ 33 myTest1, 34 } 35 functional.RunSuite(ctx, "My suite", tests) 36 } 37 38 func myTest1(t *functional.T) { 39 t.Log("Hello World.") 40 } 41 ``` 42 43 ## Testify Assertions 44 Testify is compatible with the functional testing framework as-is. 45 46 ```go 47 import ( 48 "github.com/mailgun/holster/v4/functional" 49 "github.com/stretchr/testify/require" 50 ) 51 52 func myTest1(t *functional.T) { 53 retval := DoSomething() 54 require.Equal(t, "OK", retval) 55 } 56 ```