Testing Go Projects
Published by O'Reilly Media, Inc.
Techniques for testing real-world Go applications from the ground up
Implementing test code for Go projects and its continuous execution is integral to ensuring your software is ready for prime time. But we developers often claim that certain pieces of software are untestable—they either have dependencies on actual services like a database or an HTTP API, require extensive setup, or simply aren’t structured properly.
Testing doesn’t have to be hard. Join expert Benjamin Muschko to learn the ropes of writing and executing tests for Go applications with the standard testing package. You’ll then apply proven testing techniques to verify hard-to-test code regularly encountered in real-world projects.
What you’ll learn and how you can apply it
By the end of this live online course, you’ll understand:
- How to implement and execute tests for Go projects
- How to apply proven testing techniques
- How to tackle real-world testing scenarios
And you’ll be able to:
- Verify the correctness of your code with sensible assertions
- Write effective test code even for complex, hard-to-test use cases
- Drive tests from the command line and an IDE
- Use testing to improve maintainability, achieve high cohesion, and reduce strong coupling of your production source code
This live event is for you because...
- You’re a Go developer new to writing tests and want to learn the basics.
- You’re a Go developer familiar with the standard testing package but want to - learn how to implement more advanced testing scenarios.
Prerequisites
- A computer with the Go runtime (13.x or higher) and an IDE (optimally GoLand or VS Code + the Go plug-in) installed
- A basic understanding of Go concepts and syntax (knowledge of a Go test framework not required)
- Familiarity with test concepts and test scenarios
Recommended preparation:
- Take Introduction to the Go Programming Language (live online training course with Jay McGavren)
- Review Head First Go (book)
Recommended follow-up:
- Watch “Testing” (lesson 12 in Ultimate Go Programming)
Schedule
The time frames are only estimates and may vary according to how the class is progressing.
Why testing? (15 minutes)
- Presentation: On the importance of testing
Testing basics (65 minutes)
- Presentation: Naming conventions and code organization; writing meaningful assertions; signaling helpful failure states; running tests; generating code coverage metrics; reporting of code coverage
- Hands-on exercises: Implement and execute a test case; produce an HTML report for code coverage metrics
- Group discussion: The trade-offs between testing exported and internal functions
- Q&A
Break (5 minutes)
Advanced techniques (80 minutes)
- Presentation: Managing test fixtures; implementing and organizing repetitive test code; running through test case permutations; using mock objects; separating and executing different types of tests
- Hands-on exercises: Set up and tear down test fixtures; implement a test helper; implement a table-driven test; test in isolation by mocking an interface; differentiating between unit and integration tests
- Q&A
Break (10 minutes)
Testing real-world scenarios (60 minutes)
- Presentation: Comparing complex output with golden files; testing HTTP endpoints; testing the behavior of CLI applications
- Hands-on exercises: Use a golden file for JSON data; avoid network calls and mock the response; test a Cobra CLI command
Wrap-up and Q&A (5 minutes)
Your Instructor
Benjamin Muschko
Benjamin Muschko is a software engineer, consultant, and trainer with more than 20 years of experience in the industry. He specializes in cloud-native application development and transformation, container solutions, DevSecOps, and Continuous Integration/Continuous Delivery implementations. Ben is an author, a frequent speaker at conferences, and an avid open source advocate.