首页 > 解决方案 > why fmt.Scanf doesn't work in golang test

问题描述

why fmt.Scanf doesn't work properly in a test file?

I have some test code as below, the test itself finishes without waiting for me to type in something.

I'm not simulating user input, the test needs someone to type with a keyboard while the it is running

package sometests

import (
    "fmt"
    "testing"
)

func TestScanf(t *testing.T) {
    fmt.Printf("type someting:\n")
    var s string
    fmt.Scanf("%s\n", &s)
    // test should wait here for me to type, but it won't
    fmt.Printf("you type: %q\n", s)
}

标签: stringtestinggoinput

解决方案


推荐阅读