3 Test driven development with actors
This chapter covers
- Unit testing actors synchronously
- Unit testing actors asynchronously
Everyone has a rapid, fluid experience on the testing unit side when testing is confined to a single component. Tests that involve integrations are where ease and speed generally evaporate rapidly. Actors provide an interesting solution to this problem for the following reasons:
- Actors are a more direct match for tests because they embody behavior (and almost all TDD has at least some BDD—behavior-driven development—in it).
- Too often, regular unit tests test only the interface, or have to test the interface and functionality separately.
- Actors are built on messaging, which has huge advantages for testing, because you can easily simulate behaviors by sending messages.
In this chapter, we’ll see two different ways of testing actors. First, we’ll look at stubbing Actor systems to test actors in isolation with deterministic guarantees. On the other side, we’ll be testing actors in a real context, where multiple actors interact with each other and abide messages that arrive in an indetermined order. Respectively, we will be testing Synchronously and Asynchronously.