Akka.NET allows easier creation of reactive, stateful, concurrent, and fault-tolerant applications through the use of actors. Due to the nature of the Actor Model, additional testing strategies and tools are required to test our actors. By the end of this course, you'll know how to set up and execute automated unit and integration tests against your actors.
Course Overview Hi everyone. My name is Jason Roberts. Welcome to my course Akka. NET Testing Fundamentals. I'm a Microsoft MVP freelance developer and author. The actor model and Akka. NET is a great tool for creating concurrent, fault-tolerant, and distributed systems. But due to the nature of the actor model, we need additional techniques to write automated tests against our code. Some of the major topics that we'll cover include writing unit tests, writing integration tests, testing correct messages are being sent, mocking out actors and dependencies, and testing against the event stream. By the end of this course, you'll know how to write both unit and integration tests to ensure your actors work as expected in isolation, and also when combined with other actors. Before beginning the course, you should be familiar with the actor model in general, and also how it's implemented in the Akka. NET Framework. I hope you'll join me on this journey to learn Akka. NET testing with the Akka. NET Testing Fundamentals course at Pluralsight.
Getting Started with TestKit Hi, I'm Jason Roberts from Pluralsight. Welcome to this course on Akka. NET Testing Fundamentals. In this module, we're going to get an overview of testing in Akka. NET and we'll introduce the Akka. NET TestKit, which allows us to write tests against our actors. So, in this module, we're going to start off getting an overview of the course structure and the suggested course prerequisites. We'll look at the different Akka. NET NuGet testing packages that are available to help us test our actors. And then we'll get a high level overview of the TestKit base class, and how we can inherit from it in our test classes. We'll learn about some of the conceptual modes of testing when we're working with actors, so we'll look at direct testing where we create an instance of our actor class outside of any actor system, we'll learn how we can unit test our actors and how this differs from traditional OO unit testing. We'll look at integration testing of actors where we have multiple actors working together, and also mixed mode testing, where we might use unit testing, for example, in conjunction with some of the techniques from the direct testing mode. And finally we'll get started in Visual Studio where we'll create a class library project to hold our actors, and also a project to hold our tests.
Writing Basic Tests Hi, welcome back. In the previous module, we got an introduction to writing tests for Akka. NET actors using the TestKit class. In this module, we're going to dig into some more detail, and actually look at some demos of writing tests to cover basic functionality. So in this module, we'll start off by getting an overview of the TestKit base class itself, and we'll learn more about the inheritance hierarchy of TestKit, and also some of the features it provides. Next we'll jump into Visual Studio, and we'll see how we can write our first direct test. So here we're just going to create an instance of the class and write typical asserts against it, so this is our actor not actually running inside an actor system. Next we'll go and write a unit test where we're actually instantiating our actor that we want to test inside the test actor system that the TestKit class provides for us. Now we've got a basic unit test with our actor running in the actor system, we can send it messages, and then use TestKit to test that we're getting the expected reply back from the actor we're testing. We'll then jump into writing tests where we have multiple actors working together. So, we'll wire up two different actors inside the actor system, and we'll send a message to one actor, and then write some asserts that the other actor was notified of the changes. In writing this integration test, we'll learn that our tests can run synchronously or asynchronously, so we'll learn more about the differences between these two types of tests. Finally, we'll found off the module by looking at some general testing guidelines that we can follow.
Additional TestKit Features Hi, welcome back to this final module. In this module, we're going to look at some of the additional TestKit features that can prove useful when testing our actors. We're going to start off with a series of demos showing how to test against the Akka. NET test actor sytem's event stream. So, by examining the event stream, we can test for things such as the correct log messages are being output by our actors, we can test if our actors should or should not be sending out undeliverable messages, so, for example, if our actor is using an actor path that doesn't exist, we can test if our actor is throwing expected exceptions at the correct time. So, for example, we can send a message and then assert that the event stream contained the expected exception message. If our actor is publishing its own custom messages to the event stream, we can also test this with TestKit. We'll then move on to some non-event stream-based testing features, so for example, we'll see how we can test if an actor was terminated or not; we'll learn how we can test that our actor sends a message to its parent when it's supposed to; if our actor is acting as a supervisor and is supposed to create its own children, we'll see how we can test that the child actors were created; and finally, we'll see how we can deal with non-deterministic message ordering. So, if we have many actors working together in an asynchronous fashion in our test, we'll see how we can get around the problem of not knowing exactly which order these messages are going to be flowing through the system, but how we can still test against the expected messages.