单元测试结果输出方式
目前支持Testing终端输出、Logrus、Tebeka重定向。
Testing终端输出
-
此种方式只支持终端打印的结果输出
-
输入样例如下:
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重定向
- 支持文件输出,内容格式为xml,目前支持的操作系统为windows,linux,暂不支持Aix
- 输出样例如下:
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="mq_exporter/component" tests="4" errors="0" failures="1" skip="0">
<testcase classname="mq_exporter/component" name="TestGetQueueTotal" time="0.09">
</testcase>
<testcase classname="mq_exporter/component" name="TestGetQueueServicesSate" time="0.06">
<failure type="go.error" message="error">
<![CDATA[Microsoft Windows [?? 10.0.17134.472]
(c) 2018 Microsoft Corporation????????
E:\Workplace_Go\src\mq_exporter\component>
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]]>
</failure> </testcase>
<testcase classname="mq_exporter/component" name="TestCreateDir" time="0.00">
</testcase>
<testcase classname="mq_exporter/component" name="TestGetTime" time="0.00">
</testcase>
</testsuite>