COSCUP2020
入門
TR214
歡迎來到 https://hackmd.io/@coscup/2020 共筆
請從這裡開始
Unit-test in Golang is simple
because of the build-in testing framework
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)
go test -cover
go tool cover -html=cover.html
testify
提供好用的 assert
函數
Nil
, NoNil
Error
, NoError
EqualValues
, JSONEq
Len
, True
, False
, Empty
另外還有一包 require
assert
與 require
差異在 assert
會繼續跑,require
會停下
講者建議的 test helper funcs
t
可以做更多testable code \(!=\) TDD
that code is testable when we don't have to change the code itself when we're adding unit test.
依賴反轉 dependency inversion
其中一個實作方法是依賴注入,讓 A
依賴於 A
自己的介面,然後把 B
注入
在單元測試時,可以自由的傳入 mock 的 B
concrete type is usually pointer or struct
gomock
透過寫 go generate comment
去產生骨架
ory/dockertest
可以做到整合 go test
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