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
CSC307 Lecture 09
javiergs
PRO
1
840
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
Patterns of Patterns
denyspoltorak
0
1.4k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
580
CSC307 Lecture 07
javiergs
PRO
0
550
CSC307 Lecture 05
javiergs
PRO
0
500
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.2k
Grafana:建立系統全知視角的捷徑
blueswen
0
330
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
270
Implementation Patterns
denyspoltorak
0
290
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.5k
Featured
See All Featured
Design in an AI World
tapps
0
140
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
WENDY [Excerpt]
tessaabrams
9
36k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
320
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Building Applications with DynamoDB
mza
96
6.9k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
Prompt Engineering for Job Search
mfonobong
0
160
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
720
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]