string - 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)
}
解决方案
推荐阅读
- docker-for-windows - percona DB 在 Windows 上的 docker 上变得非常慢
- generics - 包含实现多个特征的泛型类型向量的 Rust 结构
- dns - 托管的 Gitlab CE 无法访问
- python - skimage.util.apply_parallel 未按预期运行
- python - 我的 Pytorch 卷积神经网络中的每个时期都应用了随机变换吗?(数据增强)
- c++ - fltk 从按钮将图像附加到窗口
- excel - 有没有办法限制在 Excel 实例中打开其他工作簿?
- python - Tensorflow 根本不会随机加载
- android - 从 ListView 更改特定元素
- python - pySerial字典混淆