Golang单元测试结果输出方式

单元测试结果输出方式

目前支持Testing终端输出、Logrus、Tebeka重定向。

Testing终端输出

  1. 此种方式只支持终端打印的结果输出

  2. 输入样例如下:

    time="2018-12-26T10:16:25+08:00" level=info msg="GetQueueTotal out values normal"
    --- PASS: TestGetQueueTotal (0.07s)
            apis_test.go:13: test gets queue total function passed
    === RUN   TestGetQueueServicesSate
           0
    
    time="2018-12-26T10:16:25+08:00" level=info msg="GetQueueServicesSate out values normal"
    --- PASS: TestGetQueueServicesSate (0.03s)
            apis_test.go:26: 0 testing mq service state function normal
    === RUN   TestCreateDir
    --- PASS: TestCreateDir (0.00s)
            utils_test.go:19: test success to create file directory function
    === RUN   TestGetTime
    --- PASS: TestGetTime (0.00s)
            utils_test.go:43: 2018-12-26.log successful test acquisition of current system time function
    PASS
    ok      mq_exporter/component   0.888s`
    

Logrus输出

​ 支持文件输出,输出的格式为TextFormatter和JSONFormatter

  • JSONFormatter的输出样例
  {"level":"info","msg":"exporter start..","time":"2018-12-26T10:56:18+08:00"}
  {"level":"info","msg":"GetQueueTotal out values normal","time":"2018-12-26T10:56:18+08:00"}
  {"level":"info","msg":"GetQueueTotal out values normal","time":"2018-12-26T10:56:19+08:00"}
  {"level":"info","msg":"GetQueueServicesSate out values normal","time":"2018-12-26T10:56:19+08:00"}
  {"level":"info","msg":"GetQueueTotal out values normal","time":"2018-12-26T10:57:03+08:00"}
  {"level":"info","msg":"GetQueueTotal out values normal","time":"2018-12-26T10:57:04+08:00"}
  {"level":"info","msg":"GetQueueServicesSate out values normal","time":"2018-12-26T10:57:04+08:00"}
  {"level":"info","msg":"GetQueueTotal out values normal","time":"2018-12-26T10:57:09+08:00"}
  {"level":"info","msg":"GetQueueTotal out values normal","time":"2018-12-26T10:57:09+08:00"}
  {"level":"info","msg":"GetQueueServicesSate out values normal","time":"2018-12-26T10:57:09+08:00"}
  • TextFormatter的输出样例:

    time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8
    time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
    time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true
    time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4
    time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009
    time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true
    

Tebeka重定向

  1. 支持文件输出,内容格式为xml,目前支持的操作系统为windows,linux,暂不支持Aix
  2. 输出样例如下:
   
     
       
       
       
         
           
   time="2018-12-24T16:45:12+08:00" level=info msg="GetQueueServicesSate out values normal"
   time="2018-12-24T16:45:12+08:00" level=error msg="strconv.Atoi: parsing \"MicrosoftWindows[\\xb0??0.0.17134.472]\\r(c)2018MicrosoftCorporation\\xa1\\xa3\\xb1\\xa3\\xc1\\xf4\\xcb\\xf9\\xd3\\xd0?\\xc0\\xfb\\xa1\\xa3\\r\\rE:\\\\Workplace_Go\\\\src\\\\mq_exporter\\\\component>\": invalid syntax" function=GetQueueServicesSate
   	apis_test.go:23: testing failed to obtain mq service state function]]>
             
       
   
       
       
   
       
     

你可能感兴趣的:(Go开发)