Writing tests in Go can be challenging without guidance on patterns and best practices. This skill provides comprehensive examples for table-driven tests, mocking, integration testing with containers, and performance benchmarks.
Télécharger le ZIP du skill
Importer dans Claude
Allez dans Paramètres → Capacités → Skills → Importer un skill
Activez et commencez Ă utiliser
Tester
Utilisation de "golang-testing". How do I write tests for a function that adds two numbers?
Résultat attendu:
- Use table-driven tests with t.Run for each case:
- Test positive numbers, negative numbers, mixed signs, and zeros
- Use t.Errorf to report failures with expected vs actual values
- Group related tests in a slice of test cases for maintainability
Audit de sécurité
SûrThis is a pure prompt-based skill containing only markdown documentation about Go testing patterns. No executable code, scripts, network calls, or file system access. The skill provides informational guidance only.
Score de qualité
Ce que vous pouvez construire
Learn Test Patterns
Master table-driven tests, mocking, and test organization for production Go code.
Integration Testing
Set up integration tests with test containers for databases and external services.
Benchmark Code
Write and run benchmarks to measure and optimize performance-critical code sections.
Essayez ces prompts
Show me how to write a table-driven test in Go for a function called Divide that takes two integers and returns the quotient and an error.
How do I create a mock for a UserRepository interface to test my UserService without a real database?
Write an integration test using testcontainers to test my repository against a real PostgreSQL database.
Show me how to write a Go benchmark for a sorting function with different input sizes.
Bonnes pratiques
- Test behavior, not implementation - focus on inputs and outputs rather than internal details
- Use t.Helper() to mark helper functions for clearer error reporting
- Run independent tests in parallel with t.Parallel() to speed up test suites
Éviter
- Avoid one test with many assertions - split into focused test cases
- Do not skip t.Cleanup() for resource management
- Avoid hardcoding test data - use test fixtures or factories instead
Foire aux questions
What Go versions are supported?
What is the maximum test complexity supported?
How do I integrate with existing test frameworks?
Does this skill modify my project files?
Why are my tests failing?
How is this different from Go's built-in testing?
Détails du développeur
Structure de fichiers
đź“„ SKILL.md