vendredi 6 avril 2018

mock Stdin and Stdout in Golang

I get confused when trying to write a test for simple console app in Golang. the function I want to test is very simple.

func SimpleFunc() {
    reader := bufio.NewReader(os.Stdin)
    output, _ := reader.ReadString('\n')
    fmt.Println(output)
}

Could you give an example how to write a test to mock stdin and stdout in Golang?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire