Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Unit Testing in Go
Search
Harits Fahreza Christyonotoputra
August 29, 2018
Programming
85
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Unit Testing in Go
Unit Testing 101 and how to implement unit testing in Go
Harits Fahreza Christyonotoputra
August 29, 2018
More Decks by Harits Fahreza Christyonotoputra
See All by Harits Fahreza Christyonotoputra
Multi-Country Architecture
haritsfahreza
0
200
Build Your Cool REST API using Node.js
haritsfahreza
0
74
Backend Engineering in Ruangguru
haritsfahreza
0
89
Cara Cerdas Menjadi Software Engineer
haritsfahreza
0
45
Other Decks in Programming
See All in Programming
残高管理から台帳サービスへの進化
artoy
1
200
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
400
AmebaブログはKMPから卒業します
kmars0605
0
190
JIS keyboard support in Omarchy
lef237
0
120
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
2
570
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
310
The Rails Doctrine Decade
koic
2
590
カツオ、ご期待ください
suneo3476
0
190
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
0
210
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
Featured
See All Featured
Balancing Empowerment & Direction
lara
6
1.3k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Between Models and Reality
mayunak
4
500
Marketing to machines
jonoalderson
1
5.9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
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]