Skip to main content

Test layout

Tests are co-located with source code in _test.go files. There is no separate test/ directory for unit tests.

TestKit

The testkit package provides helpers for actor-level testing. See TestKit for full documentation.
  • TestKit β€” Creates a throwaway actor system. Provides Spawn, SpawnChild, Kill, Subscribe, NewProbe, NewGrainProbe, GrainIdentity.
  • Probe β€” Test actor that records messages. Assertions: ExpectMessage, ExpectMessageOfType, ExpectNoMessage, ExpectTerminated; Send, SendSync; Watch, WatchNamed.
  • GrainProbe β€” Similar for grain testing.
  • MultiNodes β€” Multi-node cluster in-process for integration tests.
Use probes instead of sleeps or polling for message assertions.

Integration tests

Tests needing real infrastructure (Consul, etcd) use testcontainers-go. Docker is required. See discovery/consul/ and discovery/etcd/ for patterns.

Mocks

Generated by mockery. Pre-built mocks in mocks/ cover Remoting, Cluster, Extension, Dependency, Provider. Use them to isolate components in unit tests.

Conventions

  • New public types or behavior changes should have test coverage
  • Prefer TestKit probes for message-level assertions
  • Use testcontainers for external infrastructureβ€”don’t assume services on the host