Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@JimLynchCodes JimLynchCodes commented Oct 24, 2019

thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.