Creating server tests

From moorestech/moorestech · View interactive version

Creating server tests is an AI agent skill from the GitHub repository moorestech/moorestech. moorestech_serverのNUnitテストを作成するスキル。テストの雛形生成、初期化パターン、命名規約、 テスト用IDの使い方を含む。 Use when: (1) moorestech_serverに新しいテストクラスを追加する時 (2) 「テストを書いて」「テストを作成して」とサーバー側のテスト作成を依頼された時 (3) 既存機能のテストカバレッジを追加する時 (4) CombinedTest/UnitTest/PacketTestのいずれかを作成する時

How to use this skill

Skill file

Server Test Creator

moorestech_serverのテスト作成ガイド。NUnit + Unity Test Frameworkを使用。

テスト種別の選択

| 種別 | 用途 | 配置先 |

|------|------|--------|

| UnitTest | 単一クラス・メソッドの検証 | Tests/UnitTest/{Layer}/{Category}/ |

| CombinedTest | 複数システムの統合検証 | Tests/CombinedTest/{Layer}/ |

| PacketTest | プロトコル通信の検証 | Tests/CombinedTest/Server/PacketTest/ |

テストファイルは moorestech_server/Assets/Scripts/Tests/ 配下の Server.Tests.asmdef に含まれる。

ワークフロー

1. テスト種別に応じたテンプレートを選択

UnitTest - 単一機能テスト:

using NUnit.Framework;
using Server.Boot;
using Tests.Module.TestMod;
using Game.Context;

namespace Tests.UnitTest.{Layer}.{Category}
{
    public class {Feature}Test
    {
        [SetUp]
        public void Setup()
        {
            var (_, serviceProvider) = new MoorestechServerDIContainerGenerator()
                .Create(new MoorestechServerDIContainerOptions(TestModDirectory.ForUnitTestModDirectory));
        }

        [Test]
        public void {動作内容}Test()
        {
            // テストコード
            Assert.AreEqual(expected, actual);
        }
    }
}

CombinedTest - 統合テスト:

using System;
using Core.Master;
using Core.Update;
using Game.Context;
using NUnit.Framework;
using Server.Boot;
using Tests.Module.TestMod;
using UnityEngine;

namespace Tests.CombinedTest.{Layer}
{
    public class {Feature}Test
    {
        [Test]
        public void {動作内容}Test()
        {
            var (_, serviceProvider) = new MoorestechServerDIContainerGenerator()
                .Create(new MoorestechServerDIContainerOptions(TestModDirectory.ForUnitTestModDirectory));

            // ブロック配置
            // Place blocks
            ServerContext.WorldBlockDatastore.TryAddBlock(
                ForUnitTestModBlockId.ChestId,
                new Vector3Int(0, 0, 0),
                BlockDirection.North,
                Array.Empty<BlockCreateParam>(),
                out var block);

            var component = block.GetComponent<TargetComponent>();

            // ゲーム更新
            // Update game
            GameUpdater.UpdateOneTick();

            Assert.AreEqual(expected, actual);

            #region Internal

            void HelperMethod() { }

            #endregion
        }
    }
}

PacketTest - テンプレートは references/packet-test.md を参照。

2. 必須ルール

3. テスト実行

作成後、uloop CLIでテスト実行(サーバーテストはクライアントプロジェクトからインポートされているため、クライアントのproject-pathで実行する):

uloop run-tests --project-path ./moorestech_client --test-mode EditMode --filter-type regex --filter-value "^Tests\.{TestType}\.{Layer}\.{ClassName}$"

注意: 新規サーバー.csファイルはUnity再起動(Refresh不可)でないとコンパイルされない(file:パッケージのため)。

リソース

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.