or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
談談 go 測試的二三事 - David Chou
tags:
COSCUP2020
入門
TR214
歡迎來到 https://hackmd.io/@coscup/2020 共筆
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。
Unit-test in Golang is simple
go test
幾個講者的 tricks
go test -v -run={TestName}
go test -race
go test -count=1
(prevent cache)go test -c -o {TextExe}
(get test code binary)Test helpers
testify
提供好用的
assert
函數Nil
,NoNil
Error
,NoError
EqualValues
,JSONEq
Len
,True
,False
,Empty
另外還有一包
require
assert
與require
差異在assert
會繼續跑,require
會停下講者建議的 test helper funcs
t
可以做更多Table-driven test
Writing testable code
testable code \(!=\) TDD
SOLID principle
依賴反轉 dependency inversion
其中一個實作方法是依賴注入,讓
A
依賴於A
自己的介面,然後把B
注入在單元測試時,可以自由的傳入 mock 的
B
Mocking
gomock
透過寫
go generate comment
去產生骨架integrate test
ory/dockertest
可以做到整合
go test
工商
GopherCon TW 2020