A comprehensive collection of Go exercises following the Test-Driven Development (TDD) approach. This repository contains my journey through learning Go by writing tests first.
learn-go-with-tests/
├── arrays/ # Working with arrays and slices
├── blogrenderer/ # HTML template rendering with snapshots
├── concurrency/ # Goroutines and concurrent operations
├── context/ # Context package for cancellation
├── di/ # Dependency injection patterns
├── generics/ # Go generics with type parameters
├── helloworld/ # Basic Hello World implementation
├── integers/ # Integer operations and examples
├── iteration/ # Loops and iteration patterns
├── maps/ # Dictionary/map operations
├── math/ # Mathematical calculations (clockface SVG)
├── mocking/ # Mocking and test doubles
├── pointers/ # Pointer operations and wallet example
├── reading-files/ # File I/O and blog post parsing
├── reflection/ # Reflection package usage
├── roman-numerals/ # Roman numeral conversion
├── select/ # Select statement and racing
├── structs/ # Struct definitions and methods
└── sync/ # Synchronization primitives
- Hello World: Basic Go syntax and testing
- Integers: Working with integer types and operations
- Iteration: Loops and repetition
- Arrays & Slices: Collection data structures
- Structs: Custom types and methods
- Pointers: Memory addresses and pointer operations
- Maps: Key-value data structures
- Dependency Injection: Decoupling code for testability
- Mocking: Creating test doubles and mocks
- Concurrency: Goroutines and concurrent execution
- Select: Managing multiple channel operations
- Reflection: Runtime type inspection
- Sync: Mutexes and synchronization primitives
- Context: Request cancellation and timeouts
- Generics: Type parameters and generic functions
- Reading Files: File I/O and parsing
- Blog Renderer: Template rendering with snapshot testing
- Roman Numerals: Algorithm implementation with TDD
- Math/SVG: Generating SVG graphics (clockface)
- Go 1.18 or higher (for generics support)
- Basic understanding of programming concepts
Run all tests:
go test ./...Run tests for a specific package:
go test ./arrays
go test ./concurrencyRun tests with verbose output:
go test -v ./...Run benchmarks:
go test -bench=. ./concurrencySome packages include executable examples:
Clockface SVG Generator:
go run ./math/clockface- Test-Driven Development (TDD): Write tests before implementation
- Go Testing: Using the
testingpackage effectively - Benchmarking: Performance testing with Go's benchmark tools
- Snapshot Testing: Testing rendered output (blogrenderer)
- Concurrent Programming: Safe concurrent code with goroutines
- Interface Design: Writing flexible, testable code
- Error Handling: Go's explicit error handling patterns
Demonstrates safe concurrent operations with benchmark tests showing performance improvements through parallelization.
Uses Go templates to render HTML with snapshot testing to verify output consistency.
Shows practical use of Go generics with a type-safe stack implementation and custom assertion helpers.
Illustrates proper context usage for cancellation and timeouts in HTTP handlers.
This project follows the Learn Go with Tests guide by Chris James.
This project is licensed under the terms specified in the LICENSE file.
This project uses GoLand/IntelliJ IDEA (configuration in .idea/ directory).
Dependencies are managed with Go modules. See go.mod for the complete list.
# Install dependencies
go mod download
# Tidy dependencies
go mod tidyThis is a personal learning repository, but feel free to use it as a reference for your own Go journey!
- ✅ Hello World
- ✅ Integers
- ✅ Iteration
- ✅ Arrays and Slices
- ✅ Structs, Methods & Interfaces
- ✅ Pointers & Errors
- ✅ Maps
- ✅ Dependency Injection
- ✅ Mocking
- ✅ Concurrency
- ✅ Select
- ✅ Reflection
- ✅ Sync
- ✅ Context
- ✅ Reading Files
- ✅ Generics
- ✅ Blog Renderer
- ✅ Math/SVG Graphics
- ✅ Roman Numerals
Happy Testing! 🚀