Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Created June 24, 2015 00:33
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vaskoz/98f2f1f0ec8f2cf0114c to your computer and use it in GitHub Desktop.
Save vaskoz/98f2f1f0ec8f2cf0114c 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{})
}
@JimLynchCodes
Copy link

thanks! 👍

@anandsunderraman
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment