Stderr io.Writer Stdin io.Reader } func (cli *CLI) Run(args []string) error { // something } // メインプログラムで使う時 cli := &mytool.CLI{ Stdout: os.Stdout, Stderr: os.Stderr, Stdin: os.Stdin, } fmt.Fprintln(cli.Stdout, ”Hello") // テストで使う時 s := “-input=hoge –output=fuga” input := “piyo” want := “correct” var got bytes.Buffer cli := &mytool.CLI{ // 置き換える Stdout: &got, Stderr: &got, Stdin: strings.NewReader(input), } args := strings.Split(s, " ") err := cli.Run(args) if got := got.String(); got != want { fmt.Printfln("want %q, but got %q", want, got) }