This document describes the testing framework for the Go Development MCP Server, including the new Go-based testing approach and the transition from the previous PowerShell-based testing.
- Introduction
- Testing Framework Overview
- Go Testing Framework
- Running Tests
- Writing New Tests
- Test Organization
- Parallel Testing
- Best Practices
The MCP Server testing framework has been redesigned to leverage Go's built-in testing capabilities, incorporate table-driven testing, and enable parallel test execution. This modernization aims to improve test reliability, speed, and maintainability.
The testing framework consists of:
- Go Tests: Modern Go tests using the
testingpackage and thetestifyframework - PowerShell Test Scripts: Legacy tests written in PowerShell (being phased out)
- Test Runner: A unified runner that supports both test types
The Go testing framework is built on standard Go testing patterns with additional structure:
- Test Suites: Using
testify/suitefor organized test grouping - Table-Driven Tests: For comprehensive test cases
- Parallel Execution: Using
t.Parallel()for concurrent testing - Fixtures: Reusable test project templates and setups
- Mocks: For isolated testing of components
internal/testing/suite.go: Base test suite implementationinternal/testing/helpers.go: Common test helper functionsinternal/testing/fixtures/: Test fixtures and datainternal/testing/mock/: Mock implementations for testinginternal/testing/parallel.go: Parallel testing coordination
The main test runner supports both PowerShell and Go tests:
# Run all tests
.\scripts\testing\run_tests.ps1 -TestType all
# Run only Go tests
.\scripts\testing\run_tests.ps1 -TestType go -UseGoTests -WithCoverage -WithRaceDetection
# Run Go tests with coverage analysis
.\scripts\testing\run_tests.ps1 -TestType go -UseGoTests -WithCoverageYou can also run Go tests directly using standard Go tools:
# Run all Go tests
go test ./internal/tools/...
# Run tests with verbose output
go test -v ./internal/tools/...
# Run tests with race detection
go test -race ./internal/tools/...
# Run a specific test
go test -v ./internal/tools/... -run TestRunToolSuiteMCP_USE_GO_TESTS: Set to "true" to enable Go tests in the main runnerMCP_TEST_PARALLEL: Set to control parallel test count (default: CPU cores - 1)
New tests should follow this pattern:
package yourpackage_test
import (
"testing"
"github.com/MrFixit96/go-dev-mcp/internal/testing"
"github.com/stretchr/testify/suite"
)
// YourTestSuite defines a test suite
type YourTestSuite struct {
testing.BaseSuite
// Add suite-specific fields
}
// SetupSuite runs before all tests in the suite
func (s *YourTestSuite) SetupSuite() {
s.BaseSuite.SetupSuite()
// Add your setup code
}
// TearDownSuite runs after all tests in the suite
func (s *YourTestSuite) TearDownSuite() {
// Add your teardown code
s.BaseSuite.TearDownSuite()
}
// TestYourFeature tests a specific feature
func (s *YourTestSuite) TestYourFeature() {
// Enable parallel execution if appropriate
testing.RunParallel(s.T())
// Your test code
s.Equal("expected", "actual")
}
// TestYourTestSuite runs the test suite
func TestYourTestSuite(t *testing.T) {
suite.Run(t, new(YourTestSuite))
}For testing multiple similar cases:
func (s *YourTestSuite) TestMultipleCases() {
testCases := []struct {
name string
input string
expected string
}{
{"empty input", "", ""},
{"normal input", "hello", "HELLO"},
{"special chars", "a!b@c#", "A!B@C#"},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
result := strings.ToUpper(tc.input)
s.Equal(tc.expected, result)
})
}
}// Create a test project
project := fixtures.SimpleProjectFixture(s.TempDir, "test-project")
err := project.Setup()
s.Require().NoError(err)
defer project.Cleanup()Tests are organized by functionality and test type:
- Unit Tests: Test individual functions or methods
- Integration Tests: Test interactions between components
- End-to-End Tests: Test complete workflows
Each test file should focus on a specific component or feature.
To enable parallel testing:
// At the beginning of each test method
testing.RunParallel(s.T())Tests that use RunParallel:
- Must be completely independent
- Should not modify global state
- Should use separate test directories
- Use Table-Driven Tests: For comprehensive testing of similar cases
- Write Isolated Tests: Ensure tests don't depend on each other
- Clean Up Resources: Always clean up temporary files and directories
- Use Assertions Properly: Use
s.Assert()for non-critical checks,s.Require()for critical checks - Test Error Cases: Always test error conditions, not just happy paths
- Keep Tests Focused: Test one thing per test method
- Use Mocks When Appropriate: Mock external dependencies for unit tests
- Include Edge Cases: Test boundaries and special conditions
As we modernize our testing approach, we're gradually transitioning from PowerShell to Go tests. The run_tests.ps1 script supports both for backward compatibility.
- Identify Tests to Migrate: Look for PowerShell tests that would benefit from Go's testing capabilities
- Create Equivalent Go Tests: Using the new framework
- Verify Both Pass: Ensure both test versions pass before removing PowerShell tests
- Remove PowerShell Tests: Once Go tests are stable and comprehensive