//go:generate go run github.com/srgg/testify/depend/cmd/dependgen
package examples
type SimpleSuite struct {
suite.Suite
}
func (s *SimpleSuite) TestA() {
// First test - no dependencies
}
// @dependsOn TestA
func (s *SimpleSuite) TestB() {
// This test depends on TestA
}
// @dependsOn TestA, TestB
func (s *SimpleSuite) TestC() {
// This test depends on BOTH TestA and TestB
}
func TestSimpleSuite(t *testing.T) {
depend.RunSuite(t, new(SimpleSuite))
}When all tests pass:
--- PASS: TestSimpleSuite/All_pass_-_no_failures (0.00s)
--- PASS: TestSimpleSuite/All_pass_-_no_failures/TestA (0.00s)
--- PASS: TestSimpleSuite/All_pass_-_no_failures/TestB (0.00s)
--- PASS: TestSimpleSuite/All_pass_-_no_failures/TestC (0.00s)
When TestA fails:
--- FAIL: TestSimpleSuite/A_fails_-_B_and_C_skipped (0.00s)
--- FAIL: TestSimpleSuite/A_fails_-_B_and_C_skipped/TestA (0.00s)
--- SKIP: TestSimpleSuite/A_fails_-_B_and_C_skipped/TestB (0.00s)
--- SKIP: TestSimpleSuite/A_fails_-_B_and_C_skipped/TestC (0.00s)
When TestB fails (but TestA passes):
--- FAIL: TestSimpleSuite/A_passes,_B_fails_-_only_C_skipped (0.00s)
--- PASS: TestSimpleSuite/A_passes,_B_fails_-_only_C_skipped/TestA (0.00s)
--- FAIL: TestSimpleSuite/A_passes,_B_fails_-_only_C_skipped/TestB (0.00s)
--- SKIP: TestSimpleSuite/A_passes,_B_fails_-_only_C_skipped/TestC (0.00s)
This demonstrates:
- Single dependencies (TestB → TestA)
- Multiple dependencies (TestC → TestA, TestB)
- Cascading skips (when A fails, both B and C skip)
- Targeted skips (when B fails, only C skips)
- Table-driven testing with dependency management
# Add the library
go get github.com/srgg/testify/depend
# Install the code generator
go install github.com/srgg/testify/depend/cmd/dependgen@latest- Add
@dependsOncomments above test methods that have dependencies - Run code generation -
go generatecreates the dependency configuration - Run your tests -
depend.RunSuite()handles dependency tracking automatically
Tests run in declaration order, automatically skipping when dependencies fail.
Create a standard testify suite with a //go:generate directive:
package mypackage_test
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/srgg/testify/depend"
)
//go:generate go run github.com/srgg/testify/depend/cmd/dependgen
type MySuite struct {
suite.Suite
// Your test data here
}Add @dependsOn comments above tests that have dependencies:
func (s *MySuite) TestSetup() {
// Setup code
}
// @dependsOn TestSetup
func (s *MySuite) TestProcess() {
// This test depends on TestSetup
}
// @dependsOn TestSetup, TestProcess
func (s *MySuite) TestValidate() {
// This test depends on BOTH TestSetup and TestProcess
}Important: Reference the full test method name, including the Test prefix.
go generate ./...This generates dependency code in <testfile>_depend_test.go (e.g., simple_test.go → simple_depend_test.go).
Note: If you have multiple test suites in the same file, they will all be generated into a single output file based on the source filename. For example:
my_test.gocontainsFirstSuiteandSecondSuite- Both generate into:
my_depend_test.go(one file, two suite configurations)
Replace suite.Run with depend.RunSuite:
func TestMySuite(t *testing.T) {
depend.RunSuite(t, new(MySuite))
}go test -vA test can depend on multiple other tests. All must pass for the test to run:
// @dependsOn TestDatabaseConnection, TestUserAuthentication
func (s *Suite) TestTransaction() {
// Runs only if BOTH dependencies passed
}When a test fails, all tests that (directly or indirectly) depend on it are automatically skipped with clear messages:
--- SKIP: .../TestC (0.00s)
depend: Skipping TestC: dependency TestA failed
Tests run in the order they're declared in your source file, making the flow easy to follow.
See depend/examples/simple_test.go for a complete, runnable example demonstrating:
- Single dependencies
- Multiple dependencies
- Table-driven tests verifying skip behavior
- Proper usage of
@dependsOncomments
To run the example:
cd depend/examples
go generate
go test -vCross-suite dependencies are not yet supported. The current implementation manages dependencies within a single test suite only. Tests in different suites cannot depend on each other.
A DAG-based cross-suite dependency runner is currently in development and will be available in a future release.
Go lacks native metadata features like Java annotations or TypeScript decorators. Comments are the cleanest way to express metadata without reflection or build hacks.
They keep things simple, decoupled, and tooling-friendly — how Go intends:
// With comments - declaration lives with the test
// @dependsOn TestUserCreation
func (s *Suite) TestUserAuth() { /* ... */ }
// vs. separate configuration - easy to forget updating
var Dependencies = depend.Depends(...)Contributions are welcome! Please open an issue before starting major work.
MIT License - see LICENSE file for details.
- Built with stretchr/testify, the excellent testing toolkit for Go.
- Development assisted by Claude Code and Serena MCP server for semantic code operations.
- Released with GoReleaser for multi-platform distribution.
Questions? Open an issue or start a discussion.
Found a bug? Please report it with a minimal reproduction case.