akka-testing-patterns_skill

This skill helps you test Akka.NET actors using Akka.Hosting.TestKit patterns with DI, TestProbes, and in-memory persistence.
  • Shell

643

GitHub Stars

3

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill aaronontheweb/dotnet-skills --skill akka-testing-patterns

  • anti-patterns-and-reference.md5.2 KB
  • examples.md28.5 KB
  • SKILL.md9.5 KB

Overview

This skill teaches modern patterns for unit and integration testing Akka.NET actors using Akka.Hosting.TestKit. It covers dependency injection, TestProbes, persistence testing, auto-responders, and when to prefer traditional TestKit. The guidance focuses on practical recipes that match production configuration and enable reliable, fast tests.

How this skill works

The approach uses Akka.Hosting.TestKit as a framework base class to spin up IHost-backed test ActorSystems with the same extension methods you use in production. Override ConfigureServices to inject fake dependencies and ConfigureAkka to register actors and test probes. Use ActorRegistry for type-safe retrieval, TestProbe for interaction verification, and in-memory persistence for event-sourced actor tests.

When to use it

  • Unit testing individual actors that depend on DI-registered services (IOptions, DbContext, ILogger, HTTP clients).
  • Integration tests for persistent actors using in-memory journal and snapshot stores.
  • Verifying message flows and actor-to-actor interactions with TestProbe.
  • Testing supervision, lifecycle, and state recovery behaviors locally.
  • Local cluster sharding experiments where cluster hosting packages are used.

Best practices

  • Prefer Akka.Hosting.TestKit for modern .NET projects (production parity and DI support).
  • Override ConfigureServices to register fake services as fields (composition, not inheritance).
  • Use ActorRegistry.Register/Get<T>() for type-safe lookups instead of hard-coded paths.
  • Use TestProbe and auto-responders to avoid Ask timeouts when an actor expects replies.
  • Disable host config file watching in tests (DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE=false) to avoid inotify exhaustion on Linux.
  • Test one actor at a time; stub dependencies with probes or fakes to keep tests focused and deterministic.

Example use cases

  • Testing OrderActor with a fake repository and fake email service to assert persistence and side effects.
  • Using a TestProbe as PaymentActor to verify that InvoiceActor sends InitiatePayment messages and handles PaymentCompleted.
  • Running event-sourced actor tests with WithInMemoryJournal and WithInMemorySnapshotStore to validate recovery.
  • Creating an auto-responding probe to satisfy Ask calls and assert messages were forwarded to the probe.
  • Switching to traditional Akka.TestKit when you need low-level ActorSystem control or work in pre-1.5 codebases.

FAQ

Use traditional TestKit for Akka.NET core development, legacy projects without Microsoft.Extensions, or when you need low-level ActorSystem configuration not provided by Akka.Hosting.

How do I avoid file watcher limits when running many tests on Linux?

Set DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE=false early in tests (ModuleInitializer) to disable host config file watching and prevent inotify exhaustion.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
akka-testing-patterns skill by aaronontheweb/dotnet-skills | VeilStrat