Testkit
Last updated
Last updated
GoAkt comes packaged with a that can help test that actors receive expected messages within unit tests. The testkit in GoAkt uses underneath the package. To test that an actor receive and respond to messages one will have to:
Create an instance of the testkit: testkit := New(ctx, t)
where ctx
is a go context and t
the instance of *testing.T
. This can be done in setup before the run of each test.
Create the instance of the actor under test. Example:testkit.Spawn(ctx, "pinger", &pinger{})
Create an instance of test probe: probe := testkit.NewProbe(ctx)
where ctx
is a go context. One can set some
Use the probe to send a message to the actor under test. Example:probe.Send("pinger", new(testpb.Ping))
for a Tell assertion and probe.SendSync("pinger", new(testpb.Ping), time.Second)
for an Ask assertion.
Assert that the actor under test has received the message and responded as expected using the methods:
Make sure to shut down the testkit and the probe. Example: probe.Stop()
, testkit.Shutdown(ctx)
where ctx
is a go context. These two calls can be in a tear down after all tests run.
To help implement unit tests in applications. See
The current implementation of the does not support clustering, extensions, or dependency injection out of the box. However, with some creative adaptation, it can still be used effectively for specific use cases. Future enhancements may extend its capabilities in these areas.