lundi 9 février 2015

Capturing stdout or fmt.Println outputs during Testing

My main file example.go has a simple fmt.Println statement, how do I capture during testing. Below is an example:


example.go



package main

import "fmt"

func main() {
fmt.Printf("testing")
a := 1
fmt.Printf(": %d", a)
}


example_test.go



package main

func Testmain(t *testing.T) {
// mainOutput := ?
if mainOutput != "testing: 1" {
t.Error("Output is not what expected!!!")
}
}


How I can capture main's fmt.Println Output to validate it. What should I replace // mainOutput := ? to capture the output. Any inputs.


Aucun commentaire:

Enregistrer un commentaire