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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
180
CSC307 Lecture 01
javiergs
PRO
0
690
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.2k
組織で育むオブザーバビリティ
ryota_hnk
0
180
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
220
CSC307 Lecture 04
javiergs
PRO
0
660
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
300
MUSUBIXとは
nahisaho
0
130
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.3k
dchart: charts from deck markup
ajstarks
3
990
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
730
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
66
Raft: Consensus for Rubyists
vanstee
141
7.3k
Rails Girls Zürich Keynote
gr2m
96
14k
Designing for Timeless Needs
cassininazir
0
130
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
290
Abbi's Birthday
coloredviolet
1
4.7k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
110
Deep Space Network (abreviated)
tonyrice
0
49
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
410
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]