Skip to content

Instantly share code, notes, and snippets.

@adam-stokes
Forked from vaskoz/programatic_tests.go
Created June 24, 2021 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-stokes/9c9951730a9f87db4be7ecbff4d8d03a to your computer and use it in GitHub Desktop.
Save adam-stokes/9c9951730a9f87db4be7ecbff4d8d03a to your computer and use it in GitHub Desktop.
Run golang tests programatically
package main
import (
"flag"
"fmt"
"testing"
)
func Test1(t *testing.T) {
if 1+2 != 3 {
t.Fail()
}
}
func Test2(t *testing.T) {
if 3*3 == 9 {
t.Fail() // WHOOPS!
}
}
func Test3(t *testing.T) {
fmt.Println("Just wanted to print here")
}
func main() {
flag.Set("test.v", "true")
testing.Main(func(pat, str string) (bool, error) { return true, nil },
[]testing.InternalTest{{"Test1String", Test1}, {"Test2String", Test2}, {"Test3String", Test3}},
[]testing.InternalBenchmark{},
[]testing.InternalExample{})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment