我有测试:package miscvar ( Trace *log.Logger Info *log.Logger Warning *log.Logger Error *log.Logger)func TestFTPGetFilesFromServer(t *testing.T) { misc.InitLogger(4) }with InitLogger is located in another packagefunc InitSimpleLogger(level int) { if level == 1 { Trace = log.New(ioutil.Discard, "[TRACE]\t", log.Ldate|log.Ltime|log.Lshortfile) Info = log.New(ioutil.Discard, "[INFO]\t", log.Ldate|log.Ltime|log.Lshortfile) Warning = log.New(ioutil.Discard, "[WARNING]\t", log.Ldate|log.Ltime|log.Lshortfile) Error = log.New(os.Stdout, "[ERROR]\t", log.Ldate|log.Ltime|log.Lshortfile) } else if level == 2 { Trace = log.New(ioutil.Discard, "[TRACE]\t", log.Ldate|log.Ltime|log.Lshortfile) Info = log.New(ioutil.Discard, "[INFO]\t", log.Ldate|log.Ltime|log.Lshortfile) Warning = log.New(os.Stdout, "[WARNING]\t", log.Ldate|log.Ltime|log.Lshortfile) Error = log.New(os.Stdout, "[ERROR]\t", log.Ldate|log.Ltime|log.Lshortfile) } else if level == 3 { Trace = log.New(os.Stdout, "[TRACE]\t", log.Ldate|log.Ltime|log.Lshortfile) Info = log.New(ioutil.Discard, "[INFO]\t", log.Ldate|log.Ltime|log.Lshortfile) Warning = log.New(os.Stdout, "[WARNING]\t", log.Ldate|log.Ltime|log.Lshortfile) Error = log.New(os.Stdout, "[ERROR]\t", log.Ldate|log.Ltime|log.Lshortfile) } else { Trace = log.New(os.Stdout, "[TRACE]\t", log.Ldate|log.Ltime|log.Lshortfile) Info = log.New(os.Stdout, "[INFO]\t", log.Ldate|log.Ltime|log.Lshortfile) Warning = log.New(os.Stdout, "[WARNING]\t", log.Ldate|log.Ltime|log.Lshortfile) Error = log.New(os.Stdout, "[ERROR]\t", log.Ldate|log.Ltime|log.Lshortfile) }}
1 回答
芜湖不芜
TA贡献1796条经验 获得超7个赞
测试不确保misc.InitSimpleLogger(4)
在依赖此函数调用的副作用的测试之前执行。将调用移至函数init()
以确保它在测试之前执行。改变
func TestFTPGetFilesFromServer(t *testing.T) { misc.InitLogger(4) }
到
func init() { misc.InitLogger(4) }
- 1 回答
- 0 关注
- 107 浏览
添加回答
举报
0/150
提交
取消