SlideShare a Scribd company logo
TDD in Go with Ginkgo and
Gomega
Presenta:
Eddy Reyes
Eddy Reyes
Founder of Mindsight
● AI for Software Project Management
● Tells you when tasks will be finished by watching code changes.
Test Driven Development
● Write the test
● Watch it fail
● Implement new code
● Test passes
I CAN HAZ
DESIGN??
Anatomy of a Test
● GIVEN: X is true
● WHEN: Y happens
● THEN: Z must be true
TDD What’s it Good For?
● Helps you create unit tests
● Tests are enforceable design spec
● Forces deep understanding of design before coding
TDD, Ain't Nobody Got Time For That
● TDD takes up front additional effort
● Tests are hard- code that reasons about the behavior of code
● Design must be understood before test is written
TDD Pro Tips
● Divide and Conquer! Work with the smallest piece possible
● Experiment, prototype, learn your design
● Throw away your prototype! Start fresh with tests first
Go testing Package
In a file named XX_test.go:
func TestMyThing(t *testing.T) {
result, err := DoMyThing()
if err == nil {
t.Error(“Failed with error:”, err)
}
if !result {
t.Error(“Expected true”)
}
}
Go Testing Capabilities (Batteries Included)
Run your tests:
$ go test -race
… Also tells you if a race condition is detected in your code
Compute test coverage:
$ go test -coverprofile=coverage.out
$ go tool cover -html=coverage.out
Alternative Testing Tools
Ginkgo / Gomega
● Jasmine clone for Go
● Ginkgo- BDD-style test specification
● Gomega- Assertion syntax
Convey
● https://github.com/smartystreets/goconvey
Example With Ginkgo / Gomega
Ginkgo Contexts
Tests with Channels + Concurrency
Mocking
net/http/httptest
● Create mock HTTP servers or clients
● Mock out HTTP interactions (simulate server responses, client responses)
Mocking
What about when you have a non-HTTP external component?
Use Interfaces!!
Here we never use
the mongo library
directly in code:
Mocking
To test code interacting with the DB:
● Create mock implementation of DBConnection
● Pass the mock into your code from the test
Eddy Reyes
@0x000edd1e
@Mindsight_Tech
linkedin.com/in/ereyes01
eddy@mindsight.io
www.mindsight.io
elr715

More Related Content

PPTX
TDD in Go with Ginkgo and Gomega
PDF
TDD and Simple Design Workshop - Session 1 - November 2018
PPTX
Exceptions: Why, When, How and Where!
PDF
Test Driven Development Powered by LEGO
PDF
Test driven development_and_puppet-cfgmgmtcamp_eu-20140402
PDF
Working With Legacy Code
PDF
ES3-2020-P2 Bowling Game Kata
PPTX
Mocking in python
TDD in Go with Ginkgo and Gomega
TDD and Simple Design Workshop - Session 1 - November 2018
Exceptions: Why, When, How and Where!
Test Driven Development Powered by LEGO
Test driven development_and_puppet-cfgmgmtcamp_eu-20140402
Working With Legacy Code
ES3-2020-P2 Bowling Game Kata
Mocking in python

What's hot (20)

PDF
TDD and Simple Design Workshop - Session 1 - March 2019
PDF
Introduction to Continuous Delivery
PDF
TDD - Designing with Expectations, not Implementations
PPTX
TDD & Refactoring
PPTX
Working Effectively with Legacy Code
PDF
Hardening
PPTX
Go/Ruby/Java: What's next?
PDF
jSession#6 - Adam Bieńkowski - JGiven - BDD testing in plain Java
PPT
The ten commandments of TDD
PPTX
Anatomy of Test Driven Development
PPTX
Is your code ready for testing?
PPTX
Workshop: Unit Testing in Python
PDF
TDD and Getting Paid
PDF
Introduction to TDD (Test Driven development) - Ahmed Shreef
PDF
TDD reloaded - JUGTAA 24 Ottobre 2012
PDF
Tdd presentation
PDF
Tdd in practice
PDF
The art of being an agile programmer
PPT
Test Driven Development Part 1
PDF
TDD python ne-april-2014
TDD and Simple Design Workshop - Session 1 - March 2019
Introduction to Continuous Delivery
TDD - Designing with Expectations, not Implementations
TDD & Refactoring
Working Effectively with Legacy Code
Hardening
Go/Ruby/Java: What's next?
jSession#6 - Adam Bieńkowski - JGiven - BDD testing in plain Java
The ten commandments of TDD
Anatomy of Test Driven Development
Is your code ready for testing?
Workshop: Unit Testing in Python
TDD and Getting Paid
Introduction to TDD (Test Driven development) - Ahmed Shreef
TDD reloaded - JUGTAA 24 Ottobre 2012
Tdd presentation
Tdd in practice
The art of being an agile programmer
Test Driven Development Part 1
TDD python ne-april-2014
Ad

Similar to Test Driven Development en Go con Ginkgo y Gomega (20)

PPTX
Testing in GO
PDF
stackconf 2024 | Test like a ninja with Go by Ivan Presenti.pdf
PDF
Jaap Groeneveld - Go Unit Testing Workshop
PDF
TDD and Unit Testing in Golang
PDF
PDF
Exploratory test - Making test soup on a nail
PPTX
Understanding TDD - theory, practice, techniques and tips.
PDF
Golang dot-testing-lite
PDF
Common Challenges & Best Practices for TDD on iOS
PPTX
Comparative Analysis Of GoLang Testing Frameworks
PDF
The Best Feature of Go – A 5 Year Retrospective
PPTX
Test Driven Development on Android (Kotlin Kenya)
PDF
We Are All Testers Now: The Testing Pyramid and Front-End Development
PPT
TDD - Christchurch APN May 2012
PDF
Software Testing Types_ A Comprehensive Overview.pdf
PPT
Test Driven Development using QUnit
PDF
Testing In Software Engineering
PDF
Agile Testing - What is it?
PDF
Testing in GO
stackconf 2024 | Test like a ninja with Go by Ivan Presenti.pdf
Jaap Groeneveld - Go Unit Testing Workshop
TDD and Unit Testing in Golang
Exploratory test - Making test soup on a nail
Understanding TDD - theory, practice, techniques and tips.
Golang dot-testing-lite
Common Challenges & Best Practices for TDD on iOS
Comparative Analysis Of GoLang Testing Frameworks
The Best Feature of Go – A 5 Year Retrospective
Test Driven Development on Android (Kotlin Kenya)
We Are All Testers Now: The Testing Pyramid and Front-End Development
TDD - Christchurch APN May 2012
Software Testing Types_ A Comprehensive Overview.pdf
Test Driven Development using QUnit
Testing In Software Engineering
Agile Testing - What is it?
Ad

More from Software Guru (20)

PDF
Hola Mundo del Internet de las Cosas
PDF
Estructuras de datos avanzadas: Casos de uso reales
PPTX
Building bias-aware environments
PDF
El secreto para ser un desarrollador Senior
PDF
Cómo encontrar el trabajo remoto ideal
PDF
Automatizando ideas con Apache Airflow
PPTX
How thick data can improve big data analysis for business:
PDF
Introducción al machine learning
PDF
Democratizando el uso de CoDi
PDF
Gestionando la felicidad de los equipos con Management 3.0
PDF
Taller: Creación de Componentes Web re-usables con StencilJS
PPTX
El camino del full stack developer (o como hacemos en SERTI para que no solo ...
PDF
¿Qué significa ser un programador en Bitso?
PDF
Colaboración efectiva entre desarrolladores del cliente y tu equipo.
PDF
Pruebas de integración con Docker en Azure DevOps
PDF
Elixir + Elm: Usando lenguajes funcionales en servicios productivos
PDF
Así publicamos las apps de Spotify sin stress
PPTX
Achieving Your Goals: 5 Tips to successfully achieve your goals
PDF
Acciones de comunidades tech en tiempos del Covid19
PDF
De lo operativo a lo estratégico: un modelo de management de diseño
Hola Mundo del Internet de las Cosas
Estructuras de datos avanzadas: Casos de uso reales
Building bias-aware environments
El secreto para ser un desarrollador Senior
Cómo encontrar el trabajo remoto ideal
Automatizando ideas con Apache Airflow
How thick data can improve big data analysis for business:
Introducción al machine learning
Democratizando el uso de CoDi
Gestionando la felicidad de los equipos con Management 3.0
Taller: Creación de Componentes Web re-usables con StencilJS
El camino del full stack developer (o como hacemos en SERTI para que no solo ...
¿Qué significa ser un programador en Bitso?
Colaboración efectiva entre desarrolladores del cliente y tu equipo.
Pruebas de integración con Docker en Azure DevOps
Elixir + Elm: Usando lenguajes funcionales en servicios productivos
Así publicamos las apps de Spotify sin stress
Achieving Your Goals: 5 Tips to successfully achieve your goals
Acciones de comunidades tech en tiempos del Covid19
De lo operativo a lo estratégico: un modelo de management de diseño

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Spectroscopy.pptx food analysis technology
sap open course for s4hana steps from ECC to s4
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Teaching material agriculture food technology
KodekX | Application Modernization Development
Programs and apps: productivity, graphics, security and other tools
Spectral efficient network and resource selection model in 5G networks
NewMind AI Weekly Chronicles - August'25 Week I
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Spectroscopy.pptx food analysis technology

Test Driven Development en Go con Ginkgo y Gomega