I am trying out Akka.net. So far I just created a simple HelloWorld-style application. Usually I am using TDD approach in my development but with Akka.net I don't know where to start with my unit testing.
After some googling I realized that original Java/Scala Akka framework uses a dedicated module akka-testkit
which is seems to be unavailable in the .Net port.
Is anybody (especially guys from markedup.com) found a way to do unit testing for actors?
[Edit] There is now a more complete and better post on how to do unit testing with Akka.NET here https://petabridge.com/blog/how-to-unit-test-akkadotnet-actors-akka-testkit/
[Old] Akka.Testkit have been ported and we aim to publish it on Nuget very soon. If you want to try it out already, you have to download the source from https://github.com/akkadotnet/akka.net
The best way to get started would be to check out our own unit tests inside Akka.NET. There are specs ported from JVM using Akka.Testkit, that should give some good examples on how to test actor systems.
For example see: https://github.com/akkadotnet/akka.net/blob/dev/src/core/Akka.Tests/Actor/ActorLifeCycleSpec.cs#L116
I'm currently working on docs for the TestKit
(should be live next week) but in the interim, I'd suggest checking out this thorough intro to the TestKit
. It covers the core and advanced API features including how to test various hiearchy patterns, async calls, virtual time, scheduled messages, etc. (disclosure: I wrote it).
I've been developing a trading platform utilizing Akka.NET, my test suite is written with the xUnit2 framework and implementing the Akka.NET TeskKit.
Akka.TestKit is used as the base class which allows you to instantiate Sys.ActorOf. This is effectively a fake ActorSystem as per the links, I'm creating a fake CommandBus (example at the bottom of the post), a very small ReceiveActor which simply captures any messages sent by the SignalProcessorExit class under test (which is simulated by the TestActor which sends any messages back to itself). The contents of the message can then be examined to test the actors behavior (so I'm not peeking inside the actual actor itself, merely verifying its behavior). I found this counter intuitive initially but once you get used to how the TestActor works things get simpler.
The constructor is generating a Fresh Fixture for each test which includes tearing down and rebuilding the Sys.ActorOf test ActorSystem.
I'm using ExpectNoMsg() and ExpectMsg(T) here to grab the message received by the TestActor and make assertions based on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With