Run tests in the actual execution environment, not just where they compile - TDD's "watch it fail" step is meaningless if tests skip or can't run where code will execute
Tests that skip or can't run in the actual execution environment don't verify anything meaningful. TDD's "watch it fail" and "watch it pass" steps require running tests where the code will actually execute, not just where it compiles.
Core Principle: Compilation ≠ Verification
Use this skill when:
t.Skip(), os.Geteuid(), or conditional executionfunc TestNetworkFeature(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Requires Linux")
}
// Test netlink, eBPF, etc.
}
On macOS development machine:
You think: "Tests pass locally, ship it!"
Reality: Code has bugs that only appear on Linux.
Session example:
TDD cycle was broken:
For Linux-specific code developed on macOS:
# DON'T: Run tests locally and skip
go test ./... # Everything "passes" (skips)
# DO: Run tests in target environment
orb run bash -c "sudo -E go test ./... -v"
TDD Cycle with Target Environment:
RED Phase:
# Write test on macOS
# Run in VM to watch it fail
orb run bash -c "sudo -E go test -v -run TestFeature"
Expected: Actual failure (undefined function, etc.)
Not: Skip or "pass"
GREEN Phase:
# Implement on macOS
# Run in VM to watch it pass
orb run bash -c "sudo -E go test -v -run TestFeature"
Expected: Actual pass
Verify: All assertions pass, no skips
REFACTOR Phase:
# Refactor code
# Run in VM to keep tests green
orb run bash -c "sudo -E go test -v ./..."
Bad:
func TestCreateNetkit(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip("Requires root")
}
// Test implementation
}
Why it's bad:
Better:
func TestCreateNetkit(t *testing.T) {
if os.Geteuid() != 0 {
t.Skip("Requires root - run in VM: orb run bash -c 'sudo -E go test'")
}
// Test implementation
}
Best:
make test-vm or similar to automateTools:
orb run bash -c "command"docker run --rm -v $(pwd):/workspace golang:latest bash -c "cd /workspace && go test"limactl shell default commandWorkflow:
# Edit code locally (macOS)
# Test in target environment (Linux VM)
orb run bash -c "cd /path/to/project && sudo -E go test -v ./..."
Don't:
if os.Geteuid() != 0 {
t.Skip("Need root")
}
Do:
# Run tests with required privileges
sudo -E go test -v ./...
Document:
## Testing
Requires root privileges:
```bash
sudo -E go test -v ./...
Or in VM:
orb run bash -c "sudo -E go test -v ./..."
### Hardware-Specific Features
**Example: eBPF, netlink, network namespaces**
```go
// NO Skip in the test itself
// Run in correct environment instead
func TestAttachXDP(t *testing.T) {
// Actual test, no skip
prog := loadXDPProgram(t)
err := attachXDP(prog, "eth0")
require.NoError(t, err)
}
README:
## Testing
Tests require:
- Linux kernel 5.15+
- CAP_BPF, CAP_NET_ADMIN
- Network interfaces
Run in OrbStack VM:
```bash
orb run bash -c "sudo -E go test -v ./..."
## Meaningless Verification
### Avoid "Does It Compile?" Checks
**Bad:**
```bash
# "Verify" eBPF package compiles
go build ./bytecode
Why it's bad:
main(), build produces nothing usefulWhat to do instead:
Good:
# Integration test actually uses the package
go test -v ./... # Tests import and use bytecode package
Before (macOS):
$ go test ./netkit -v
=== RUN TestCreatePair
netkit_test.go:13: Requires root privileges
--- SKIP: TestCreatePair (0.00s)
"Tests pass!" (Wrong - they skipped)
After (OrbStack VM):
$ orb run bash -c "sudo -E go test ./netkit -v"
=== RUN TestCreatePair/create_L3_pair
netkit_test.go:51: failed to find peer "test0p"
--- FAIL: TestCreatePair/create_L3_pair (0.02s)
Found real bug! Fixed peer naming.
Final (VM, fixed):
$ orb run bash -c "sudo -E go test ./netkit -v"
=== RUN TestCreatePair/create_L3_pair
--- PASS: TestCreatePair/create_L3_pair (0.02s)
Actual verification.
Before marking TDD work complete:
t.Skip() that you never see runBad Workflow:
Good Workflow:
TDD requires running tests where code executes. Skipping tests breaks the cycle.