Token导航 LogoToken导航TokenDH.com
开发敏感数据github未标认证来源可访问许可证需确认审计通过

akka-net-testing-patternsakka 网测试模式

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

4,455

周安装

182

GitHub Stars

890

下载量

1,441
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:akka-net-testing-patterns(akka 网测试模式)
来源仓库:https://github.com/aaronontheweb/dotnet-skills
仓库路径:skills/akka-net-testing-patterns
安装命令:
npx skills add https://github.com/aaronontheweb/dotnet-skills --skill akka-net-testing-patterns
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/aaronontheweb/dotnet-skills --skill akka-net-testing-patterns

简介

用于编写 Akka.NET Actor 单元测试、持久化验证和集群行为模拟。

  • 支持事件溯源测试、依赖 Mock 和本地集群分片仿真。
  • 适合确保 Actor 状态恢复、消息流正确性和监督策略有效性。
  • 安装前建议确认权限范围和维护状态,以及是否会执行测试脚本或读取夹具数据。
  • akka-net-testing-patterns 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Akka.NET Testing Patterns

When to Use This Skill

Use this skill when:

  • Writing unit tests for Akka.NET actors
  • Testing persistent actors with event sourcing
  • Verifying actor interactions and message flows
  • Testing actor supervision and lifecycle
  • Mocking external dependencies in actor tests
  • Testing cluster sharding behavior locally
  • Verifying actor state recovery and persistence

Reference Files

Choosing Your Testing Approach

Use Akka.Hosting.TestKit (Recommended for 95% of Use Cases)

When:

  • Building modern.NET applications with Microsoft.Extensions.DependencyInjection
  • Using Akka.Hosting for actor configuration in production
  • Need to inject services into actors (IOptions, DbContext, ILogger, HTTP clients, etc.)
  • Testing applications that use ASP.NET Core, Worker Services, or.NET Aspire
  • Working with modern Akka.NET projects (Akka.NET v1.5+)

Advantages:

  • Native dependency injection support - override services with fakes in tests
  • Configuration parity with production (same extension methods work in tests)
  • Clean separation between actor logic and infrastructure
  • Type-safe actor registry for retrieving actors

Use Traditional Akka.TestKit

When:

  • Contributing to Akka.NET core library development
  • Working in environments without Microsoft.Extensions (console apps, legacy systems)
  • Legacy codebases using manual Props creation without DI

See anti-patterns-and-reference.md for traditional TestKit patterns.


Core Principles (Akka.Hosting.TestKit)

  1. Inherit from Akka.Hosting.TestKit.TestKit - This is a framework base class, not a user-defined one
  2. Override ConfigureServices() - Replace real services with fakes/mocks
  3. Override ConfigureAkka() - Configure actors using the same extension methods as production
  4. Use ActorRegistry - Type-safe retrieval of actor references
  5. Composition over Inheritance - Fake services as fields, not base classes
  6. No Custom Base Classes - Use method overrides, not inheritance hierarchies
  7. Test One Actor at a Time - Use TestProbes for dependencies
  8. Match Production Patterns - Same extension methods, different AkkaExecutionMode

Required NuGet Packages

<ItemGroup>
  <!-- Core testing framework -->
  <PackageReference Include="Akka.Hosting.TestKit" Version="*" />

  <!-- xUnit (or your preferred test framework) -->
  <PackageReference Include="xunit" Version="*" />
  <PackageReference Include="xunit.runner.visualstudio" Version="*" />
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="*" />

  <!-- Assertions (recommended) -->
  <PackageReference Include="FluentAssertions" Version="*" />

  <!-- In-memory persistence for testing -->
  <PackageReference Include="Akka.Persistence.Hosting" Version="*" />

  <!-- If testing cluster sharding -->
  <PackageReference Include="Akka.Cluster.Hosting" Version="*" />
</ItemGroup>

CRITICAL: File Watcher Fix for Test Projects

Akka.Hosting.TestKit spins up real IHost instances, which by default enable file watchers for configuration reload. When running many tests, this exhausts file descriptor limits on Linux (inotify watch limit).

Add this to your test project - it runs before any tests execute:

// TestEnvironmentInitializer.cs
using System.Runtime.CompilerServices;

namespace YourApp.Tests;

internal static class TestEnvironmentInitializer
{
    [ModuleInitializer]
    internal static void Initialize()
    {
        // Disable config file watching in test hosts
        // Prevents file descriptor exhaustion (inotify watch limit) on Linux
        Environment.SetEnvironmentVariable("DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE", "false");
    }
}

Why this matters:

  • [ModuleInitializer] runs automatically before any test code
  • Sets the environment variable globally for all IHost instances
  • Prevents cryptic inotify errors when running 100+ tests
  • Also applies to Aspire integration tests that use IHost

Testing Patterns Overview

Each pattern below has a condensed description. See examples.md for complete code samples.

Pattern 1: Basic Actor Test

The foundation pattern. Override ConfigureServices() to inject fakes, override ConfigureAkka() to register actors with the same extension methods as production.

public class OrderActorTests : TestKit
{
    private readonly FakeOrderRepository _fakeRepository = new();

    protected override void ConfigureServices(HostBuilderContext context, IServiceCollection services)
    {
        services.AddSingleton<IOrderRepository>(_fakeRepository);
    }

    protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
    {
        builder.WithInMemoryJournal().WithInMemorySnapshotStore();
        builder.WithActors((system, registry, resolver) =>
        {
            registry.Register<OrderActor>(system.ActorOf(resolver.Props<OrderActor>(), "order-actor"));
        });
    }

    [Fact]
    public async Task CreateOrder_Success_SavesToRepository()
    {
        var orderActor = ActorRegistry.Get<OrderActor>();
        var response = await orderActor.Ask<OrderCommandResult>(
            new CreateOrder("ORDER-123", "CUST-456", 99.99m), RemainingOrDefault);
        response.Status.Should().Be(CommandStatus.Success);
        _fakeRepository.SaveCallCount.Should().Be(1);
    }
}

Pattern 2: TestProbe for Actor Interactions

Register a TestProbe in the ActorRegistry as a stand-in for a dependency actor. Use ExpectMsgAsync<T>() to verify messages were sent.

Pattern 3: Auto-Responding TestProbe

When the actor under test uses Ask to communicate with dependencies, create an auto-responder actor that forwards messages to a probe AND replies to avoid timeouts.

Pattern 4: Testing Persistent Actors

Use WithInMemoryJournal() and WithInMemorySnapshotStore(). Test recovery by killing the actor with PoisonPill and querying to force recovery from journal.

Pattern 5: Reuse Production Configuration

Always reuse production extension methods in tests instead of duplicating HOCON config. This ensures tests use the exact same configuration as production.

protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
{
    builder
        .AddDraftSerializer()                                    // Same as production
        .AddOrderDomainActors(AkkaExecutionMode.LocalTest)      // Same, but local mode
        .WithInMemoryJournal().WithInMemorySnapshotStore();      // Test-specific overrides
}

Pattern 6: Cluster Sharding Locally

Use AkkaExecutionMode.LocalTest with GenericChildPerEntityParent to test sharding behavior without an actual cluster. Same extension methods, different mode.

Pattern 7: AwaitAssertAsync for Async Operations

Use AwaitAssertAsync when actors perform async operations. It retries assertions until they pass or timeout, preventing flaky tests.

await AwaitAssertAsync(() =>
{
    _fakeReadModelService.SyncCallCount.Should().BeGreaterOrEqualTo(1);
}, TimeSpan.FromSeconds(3));

Pattern 8: Scenario-Based Integration Tests

Test complete business workflows end-to-end with multiple actors and state transitions. Register all domain actors, verify state at each step.


Common Patterns Summary

PatternUse Case
Basic Actor TestSingle actor with injected services
TestProbeVerify actor sends messages to dependencies
Auto-ResponderAvoid Ask timeouts when testing
Persistent ActorTest event sourcing and recovery
Cluster ShardingTest sharding behavior locally
AwaitAssertAsyncHandle async operations in actors
Scenario TestsEnd-to-end business workflows

Best Practices

  1. One test class per actor - Keep tests focused
  2. Override ConfigureServices/ConfigureAkka - Don't create base classes
  3. Use fakes, not mocks - Simpler, more maintainable
  4. Test one actor at a time - Use TestProbes for dependencies
  5. Match production patterns - Same extension methods, different AkkaExecutionMode
  6. Use AwaitAssertAsync for async - Prevents flaky tests
  7. Test recovery - Kill and restart actors to verify persistence
  8. Scenario tests for workflows - Test complete business flows end-to-end
  9. Keep tests fast - In-memory persistence, no real databases
  10. Use meaningful names - Scenario_FirstTimePurchase_SuccessfulPayment

Debugging Tips

  1. Enable debug logging - Pass LogLevel.Debug to TestKit constructor
  2. Use ITestOutputHelper - See actor system logs in test output
  3. Inspect TestProbe - Check probe.Messages to see what was sent
  4. Query actor state - Add state query messages for debugging
  5. Use AwaitAssertAsync with logging - See why assertions fail
  6. Check ActorRegistry - Verify actors are registered correctly
// Constructor with debug logging
public OrderActorTests(ITestOutputHelper output)
    : base(output: output, logLevel: LogLevel.Debug)
{
}

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.29%
按下载量换算523

Claude

30.61%
按下载量换算441

Cursor

16.67%
按下载量换算240

Gemini CLI

8.95%
按下载量换算129

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills