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
68
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
180
Build Your Cool REST API using Node.js
haritsfahreza
0
68
Backend Engineering in Ruangguru
haritsfahreza
0
80
Cara Cerdas Menjadi Software Engineer
haritsfahreza
0
42
Other Decks in Programming
See All in Programming
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
ノイジーネイバー問題を解決する 公平なキューイング
occhi
0
100
Package Management Learnings from Homebrew
mikemcquaid
0
220
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
300
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
270
Raku Raku Notion 20260128
hareyakayuruyaka
0
180
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
730
CSC307 Lecture 02
javiergs
PRO
1
780
Basic Architectures
denyspoltorak
0
680
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
2026年 エンジニアリング自己学習法
yumechi
0
140
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.7k
Building Applications with DynamoDB
mza
96
6.9k
What does AI have to do with Human Rights?
axbom
PRO
0
2k
Are puppies a ranking factor?
jonoalderson
1
2.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
130
Designing for Performance
lara
610
70k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
110
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
120
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
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]