SlideShare a Scribd company logo
Testing in Go
TDC 2016 - São Paulo
Eduardo Bonet
$ whoami
ebonet.me
Agenda
Objectives
The Testing package
Table Testing
Testing HTTP
Other Testing Packages
Objectives
Present the basis for efficient test in Go focusing on the standard library, but with
a quick glance at some alternatives.
Why Testing?
Improves focus while developing
Avoids breaking old cold
Verify if machines are working properly
Documentation
…….
go test
go test // testing the local package
go test some/pkg // testing a specific package
go test -v some/pkg -run ^TestSum$ // runs the specified tests
go test --cover // Code coverage
https://golang.org/src/cmd/go/test.go
Testing in Go
Tests are written on files ending with "_test.go"
A Test is a function that starts with Test* and has only the parameter *testing.T
Plugin support for tests
Plugin support for tests
Atom (go-plus) Vim (vim-go) IntelliJ
Running full suites
Run specific test
Code Coverage
Others Keybindings for quick
switch
Vim-go
Coverage
Test Results
vim-go
Coverage
IntelliJ
Test Results
IntelliJ
Example: Simplified Blackjack
Simplified BlackJack
Uses a deck.
Cards from 2 to 9 are worth their face value
Figures worth 10 points
Ace is worth 11 points
Ace + Figure = Blackjack
If over 21, the hand is busted.
Implementing testing - Score Computation
A Hand is represented by a string, where each char represents a card ("AJ" is a
blackjack)
[master] blackjack_test.go
[master] blackjack_test.go
REPETITIO
N
[master] blackjack_test.go
Table Testing
Using anonymous structs to represent test cases
[master] blackjack_test.go
Testing in go
[master] blackjack_test.go
[master] blackjack_test.go
[master] blackjack_test.go
Auxiliary Functions
Testing Floats
[master] main_test.go
Auxiliary Functions
Testing Floats
[master] main_test.go
PRECISÃO
NUM
ÉRICA
Auxiliary Functions
Testing Floats
[master] main_test.go
Auxiliary Functions
valor, existe := mapa["key"]
[master] main_test.go
Testing HTTP - BlackJack
Let's create a simple BlackJack API that computes the hand result:
GET /blackjack
● Parameters
○ hand [string] : the hand
● Returns
○ [422], if 'hand' is not found or invalid
○ [200, result] if 'hand' is valid
Testing HTTP - BlackJack
[master] blackjack.go
Testing HTTP - BlackJack
https://golang.org/pkg/net/http/httptest/
Utililty package to test http.
Provides the struct *ResponseRecorder, that implements the interface
*ResponseWriter
Testing HTTP - BlackJack
[master] blackjack_test.go
Testando HTTP - BlackJack
[master] blackjack_test.go
Other Packages
Ginkgo
http://onsi.github.io/ginkgo/ (1075 )
BDD
Works with go test, but has it's own structure
Uses a custom lib for assertion (Gomega)
Rerun testes on change
ginkgo
Testing Scoring [code]
ginkgo
Table Testing [code]
Ginkgo - Results
GoConvey
http://goconvey.co/ (2334 )
BDD alike
Pretty browser interface
Reload tests on file changes
Custom DSL
goconvey
Testing Scoring [code]
goconvey
Table Testing [code]
goconvey
Results
goconvey
Failed test
Testify
https://github.com/stretchr/testify (2025 )
Run within go test
Additional testing functionality, mostly shortcuts
Mocking
Conclusion
Testing in go is very easy
For microservices, the standard library is more than sufficient
For larger apps, GoConvey or Ginkgo can speed up development process and
documentation, at the cost of losing integration with IDEs
Thank you!
Slides at ebonet.me/talks
Code at github.com/ebonet/gotesting

More Related Content

PDF
TDD and Unit Testing in Golang
PPTX
Test Driven Development
PDF
Introduction to Go programming language
PPTX
Loops PHP 04
PPTX
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
PPTX
Software Testing Life Cycle – A Beginner’s Guide
PPTX
Functional Testing
PDF
Effective testing with pytest
TDD and Unit Testing in Golang
Test Driven Development
Introduction to Go programming language
Loops PHP 04
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing Life Cycle – A Beginner’s Guide
Functional Testing
Effective testing with pytest

What's hot (20)

PPTX
Introduction to Automation Testing
PDF
AngularJS - Services
PDF
[AUG]개발자와 QA가 상생하는 테스트 프로세스
PDF
Documenting your REST API with Swagger - JOIN 2014
PPT
Manual testing concepts course 1
PPTX
Automation Testing with Test Complete
PDF
Performance tests with Gatling (extended)
PPT
Testing with test_complete
PDF
An Introduction to Test Driven Development
PPTX
Karate DSL
PPTX
Stlc ppt
ODT
Testing in-python-and-pytest-framework
PDF
github-actions.pdf
PPT
TDD (Test Driven Design)
PPTX
TestNG Session presented in PB
PDF
Py.test
PPT
Basic software-testing-concepts
PPTX
Core java complete ppt(note)
PDF
Test Driven Development for Embedded C
PPTX
TestNG Framework
Introduction to Automation Testing
AngularJS - Services
[AUG]개발자와 QA가 상생하는 테스트 프로세스
Documenting your REST API with Swagger - JOIN 2014
Manual testing concepts course 1
Automation Testing with Test Complete
Performance tests with Gatling (extended)
Testing with test_complete
An Introduction to Test Driven Development
Karate DSL
Stlc ppt
Testing in-python-and-pytest-framework
github-actions.pdf
TDD (Test Driven Design)
TestNG Session presented in PB
Py.test
Basic software-testing-concepts
Core java complete ppt(note)
Test Driven Development for Embedded C
TestNG Framework
Ad

Viewers also liked (20)

PDF
Arquitetura de dados em stream - TDC SP 2016
PDF
Go no Luiza Labs
ODP
Revolução Go TDC 2016
PDF
Go Lang migrating billions of documents
PDF
Guia do Mercado Laboral 2015 - Hays Portugal
PPT
Revisiting the SCHIP Funding Formula
PDF
PMP_Course_Certificate
DOCX
Internet en la educación2
PPTX
TDC2016SP - Entrega Contínua com Xamarin: Monte sua esteira
PDF
TDC2016SP - Buscas inteligentes para emegencias hospitalares
PPT
TDC2016SP - Trilha Startups
PDF
TDC2016SP - Trilha BigData
PPTX
TDC2016SP - Trilha BigData
PDF
TDC2016SP - Trilha Linux Embarcado
PDF
TDC2016SP - O bê-a-bá da fila de processamento para você deixar o ThreadPool ...
PDF
TDC2016SP - Trilha Linux Embarcado
PDF
TDC2016SP - Trilha Linux Embarcado
PPT
TDC2016SP - Protocolo Firmata - controle o Arduino com sua linguagem favorita
Arquitetura de dados em stream - TDC SP 2016
Go no Luiza Labs
Revolução Go TDC 2016
Go Lang migrating billions of documents
Guia do Mercado Laboral 2015 - Hays Portugal
Revisiting the SCHIP Funding Formula
PMP_Course_Certificate
Internet en la educación2
TDC2016SP - Entrega Contínua com Xamarin: Monte sua esteira
TDC2016SP - Buscas inteligentes para emegencias hospitalares
TDC2016SP - Trilha Startups
TDC2016SP - Trilha BigData
TDC2016SP - Trilha BigData
TDC2016SP - Trilha Linux Embarcado
TDC2016SP - O bê-a-bá da fila de processamento para você deixar o ThreadPool ...
TDC2016SP - Trilha Linux Embarcado
TDC2016SP - Trilha Linux Embarcado
TDC2016SP - Protocolo Firmata - controle o Arduino com sua linguagem favorita
Ad

Similar to Testing in go (20)

PPTX
Testing in GO
PPTX
TDD in Go with Ginkgo and Gomega
PDF
A Tour of Go - Workshop
PPTX
Comparative Analysis Of GoLang Testing Frameworks
PDF
Jaap Groeneveld - Go Unit Testing Workshop
PDF
Golang dot-testing-lite
PDF
Test Driven Development en Go con Ginkgo y Gomega
PDF
stackconf 2024 | Test like a ninja with Go by Ivan Presenti.pdf
PDF
Go testunderthehood
PDF
GoCracow #5 Bartlomiej klimczak - GoBDD
PDF
The Best Feature of Go – A 5 Year Retrospective
PDF
Geek Talk Backend Unit Testing in Go Language
PDF
Go 1.10 Release Party - PDX Go
PPTX
The GO Language : From Beginners to Gophers
PPTX
presentation des google test dans un contexte de tdd
PDF
How to not write a boring test in Golang
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PPTX
PPTX
PDF
Embedded Recipes 2019 - Testing firmware the devops way
Testing in GO
TDD in Go with Ginkgo and Gomega
A Tour of Go - Workshop
Comparative Analysis Of GoLang Testing Frameworks
Jaap Groeneveld - Go Unit Testing Workshop
Golang dot-testing-lite
Test Driven Development en Go con Ginkgo y Gomega
stackconf 2024 | Test like a ninja with Go by Ivan Presenti.pdf
Go testunderthehood
GoCracow #5 Bartlomiej klimczak - GoBDD
The Best Feature of Go – A 5 Year Retrospective
Geek Talk Backend Unit Testing in Go Language
Go 1.10 Release Party - PDX Go
The GO Language : From Beginners to Gophers
presentation des google test dans un contexte de tdd
How to not write a boring test in Golang
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Embedded Recipes 2019 - Testing firmware the devops way

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Big Data Technologies - Introduction.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Machine Learning_overview_presentation.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
A Presentation on Artificial Intelligence
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
SOPHOS-XG Firewall Administrator PPT.pptx
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Big Data Technologies - Introduction.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Machine Learning_overview_presentation.pptx
Getting Started with Data Integration: FME Form 101
NewMind AI Weekly Chronicles - August'25-Week II
Network Security Unit 5.pdf for BCA BBA.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Testing in go