mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-11 02:33:10 +08:00
Translated 85 skill sub-reference files to achieve full parity with the English source: - skills/angular-developer/references/ — 35 files (all references) - skills/remotion-video-creation/rules/ — 28 files (all rules) - skills/tinystruct-patterns/references/ — 5 files - skills/openclaw-persona-forge/references/ — 6 files - skills/skill-comply/prompts/ — 3 files - skills/lead-intelligence/agents/ — 4 files - skills/brand-voice/references/ — 1 file - skills/frontend-slides/ — 2 files - hooks/memory-persistence/README.md — 1 file English source parity: 0 missing files (excluding rules/zh/, internal docs, and experimental examples absent from zh-CN)
2.7 KiB
2.7 KiB
tinystruct テストパターン
使用場面
JUnit 5 でtinystruct アプリケーションのユニットテストを作成する場合に、ここで説明するテストパターンを使用します。これらのパターンは @Action メソッドが正しい結果を返し、ルーティングロジックがシングルトン ActionRegistry 内に適切に登録されていることを検証するために不可欠です。
動作の仕組み
tinystruct アプリケーションのテストには、アノテーション処理や設定管理などのフレームワークレベルの機能がアクティブであることを保証するための特定のセットアップが必要です。setUp() メソッドでアプリケーションの新しいインスタンスを作成して Settings オブジェクトを渡すことで、init() ライフサイクルをトリガーします。これにより、すべての @Action メソッドが検出されて登録されることが保証されます。
ActionRegistry はシングルトンであるため、テスト間で副作用が漏れるのを防ぐため、各テスト実行前にアプリケーションの状態を適切に初期化してテストの分離を維持することが重要です。
例
アプリケーションのユニットテスト
import org.junit.jupiter.api.*;
import org.tinystruct.application.ActionRegistry;
import org.tinystruct.system.Settings;
class MyAppTest {
private MyApp app;
@BeforeEach
void setUp() {
app = new MyApp();
Settings config = new Settings();
app.setConfiguration(config);
app.init(); // @Actionアノテーション処理をトリガー
}
void testHello() throws Exception {
// アプリケーションオブジェクト経由の直接呼び出し
Object result = app.invoke("hello");
Assertions.assertEquals("Hello, tinystruct!", result);
}
@Test
void testGreet() throws Exception {
// 引数付きの呼び出し
Object result = app.invoke("greet", new Object[]{"James"});
Assertions.assertEquals("Hello, James!", result);
}
}
ActionRegistry経由のテスト
ルーティングロジック自体をテストする必要がある場合は、ActionRegistry シングルトンを使用してパスマッチングを検証します:
@Test
void testRouting() {
ActionRegistry registry = ActionRegistry.getInstance();
// パスがアクションにマッチするか検証
Action action = registry.getAction("greet/James");
Assertions.assertNotNull(action);
}
参照:src/test/java/org/tinystruct/application/ActionRegistryTest.java