Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Unit Testing in Go
Search
Harits Fahreza Christyonotoputra
August 29, 2018
Programming
0
61
Unit Testing in Go
Unit Testing 101 and how to implement unit testing in Go
Harits Fahreza Christyonotoputra
August 29, 2018
Tweet
Share
More Decks by Harits Fahreza Christyonotoputra
See All by Harits Fahreza Christyonotoputra
Multi-Country Architecture
haritsfahreza
0
170
Build Your Cool REST API using Node.js
haritsfahreza
0
68
Backend Engineering in Ruangguru
haritsfahreza
0
79
Cara Cerdas Menjadi Software Engineer
haritsfahreza
0
39
Other Decks in Programming
See All in Programming
Discover Metal 4
rei315
2
110
すべてのコンテキストを、 ユーザー価値に変える
applism118
2
1.1k
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
180
NPOでのDevinの活用
codeforeveryone
0
710
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1.2k
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
21
3.8k
VS Code Update for GitHub Copilot
74th
2
580
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
460
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
260
PipeCDのプラグイン化で目指すところ
warashi
1
240
WindowInsetsだってテストしたい
ryunen344
1
230
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
350
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
Practical Orchestrator
shlominoach
188
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Balancing Empowerment & Direction
lara
1
400
A designer walks into a library…
pauljervisheath
207
24k
Site-Speed That Sticks
csswizardry
10
680
Faster Mobile Websites
deanohume
307
31k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
For a Future-Friendly Web
brad_frost
179
9.8k
Why Our Code Smells
bkeepers
PRO
337
57k
The Cult of Friendly URLs
andyhume
79
6.5k
Transcript
Unit Testing in Go Harits Fahreza Christyonotoputra
[email protected]
Unit Testing? “One of the methods that used to make
sure your code is not broke” “...unit tests are not an effective way to find bugs or detect regressions. They examine each unit of your code separately”
import “testing”
None
None
> go test
> go test -cover
Tips for writing a good Unit Test
Do • Make Them Short • Make Them Fast •
100% Pass • Give a good name • Design your test • Try it by yourself
Don’t • Repeat Yourself • < 100% Pass • Hard
to Read
Cool Libs
github.com/stretchr/testify
github.com/vektra/mockery
github.com/Selvatico/go-mocket
github.com/Selvatico/go-mocket
github.com/jarcoal/httpmock
Want more? github.com/avelino/awesome-go#testing
Conclusion • Unit Test just to make sure your code
is not broke • It is not an effective way to find bugs or detect regressions • It examine each unit of your code separately • Go has default `testing` package • There are tools and libs that can help us to make a good unit test
References • https://blog.alexellis.io/golang-writing-unit-tests/ • http://blog.stevensanderson.com/2009/08/24/writing-great -unit-tests-best-and-worst-practises/ • https://dzone.com/articles/10-tips-to-writing-good-unit-tests
Next Stop? • TDD • Improve Code Quality • Integration
Test
Maturnuwun! Harits Fahreza Christyonotoputra
[email protected]