Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

unity-testing

/unity-testing

Prowadzi testowanie w Unity Test Framework: testy EditMode i PlayMode, korutyny [UnityTest], Test Runner, mockowanie czasu i wejścia, testy wydajności oraz uruchomienia w CI.

Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Prowadzi testowanie w Unity Test Framework: testy EditMode i PlayMode, korutyny [UnityTest], Test Runner, mockowanie czasu i wejścia, testy wydajności oraz uruchomienia w CI.

Oryginalny opis (EN)

Unity Test Framework — EditMode + PlayMode tests, [UnityTest] coroutines, Test Runner, mocking patterns, Unity.PerformanceTesting package. USE WHEN: writing/debugging tests, setting up CI test runs, performance regression tests, asserting scene state, mocking time/input. DO NOT USE FOR: runtime in-game telemetry (use `unity-performance` for profiling); end-to-end automation (use editor tooling + custom harness).

Jak działa

  1. Test types
  2. Asmdef setup
  3. EditMode test
  4. PlayMode test ([UnityTest])
  5. Mocking time / input
  6. Performance tests (Unity.PerformanceTesting package)
  7. CI integration
  8. Anti-patterns
  9. Production checklist
Sekcje z nagłówków SKILL.md, w oryginale · 118 linii, 433 słów
Podgląd SKILL.md
---
name: unity-testing
description: |
  Unity Test Framework — EditMode + PlayMode tests, [UnityTest] coroutines,
  Test Runner, mocking patterns, Unity.PerformanceTesting package.

  USE WHEN: writing/debugging tests, setting up CI test runs, performance
  regression tests, asserting scene state, mocking time/input.

  DO NOT USE FOR: runtime in-game telemetry (use `unity-performance` for
  profiling); end-to-end automation (use editor tooling + custom harness).
allowed-tools: Read, Grep, Glob, Write, Edit
---

# Unity Test Framework

## Test types

| Mode | What | Speed |
|---|---|---|
| **EditMode** | Pure C# logic, no scene | Fast (~ms) |
| **PlayMode** | Runs in play mode, can Instantiate, FixedUpdate ticks | Slow (seconds) |

Default to EditMode; reserve PlayMode for things that genuinely need the engine loop.

## Asmdef setup

```
Assets/Tests/EditMode.asmdef     (Test Assemblies + Editor-only references)
Assets/Tests/PlayMode.asmdef     (Test Assemblies + runtime + editor)
```

Add **Test Assemblies** flag in asmdef Inspector.

## EditMode test

```csharp
using NUnit.Framework;

public class HealthTests {
    [Test] public void TakeDamage_ReducesHealth() {
        var h = new Health(100);
        h.TakeDamage(30);
        Assert.AreEqual(70, h.Current);
    }

    [TestCase(100, 200, 0)]
    [TestCase(100, 50, 50)]
    public void Damage_ClampsAtZero(int max, int dmg, int expected) {
        var h = new Health(max);
        h.TakeDamage(dmg);
        Assert.AreEqual(expected, h.Current);
    }
}
```

## PlayMode test (`[UnityTest]`)

```csharp
using UnityEngine.TestTools;
using System.Collections;
using UnityEngine;

public class JumpTests {
    [UnityTest] public IEnumerator Jump_LeavesGroundForOneSecond() {
        var go = new GameObject("Player", typeof(Rigidbody), typeof(PlayerJump));
        go.transform.position = Vector3.up;
        var jump = go.GetComponent<PlayerJump>();
        jump.DoJump();
        yield return new WaitForSeconds(1f);
        Assert.IsTrue(go.transform.position.y > 1f);
        Object.Destroy(go);
    }
}
```

`yield return null` → next frame; `WaitForSeconds`, `WaitForFixedUpdate`, `WaitUntil(() => …)`.

## Mocking time / input

- **Time**: inject an `ITime` abstraction that wraps `Time.deltaTime`; in tests pass a fake.
- **Input**: don't read `_action.ReadValue` directly in test target — pass values via method, or use `InputTestFixture` for low-level input simulation.

## Performance tests (`Unity.PerformanceTesting` package)

```csharp
[Test, Performance]
public void Pathfinder_PerfBaseline() {
    Measure.Method(() => Pathfinder.FindPath(start, end, grid))
           .WarmupCount(10)
           .MeasurementCount(50)
           .Run();
}
```

Reports captured to `PerformanceTests` folder; CI baselines via Performance Test Reporter.

## CI integration

```bash
Unity -batchmode -projectPath . \
  -runTests -testPlatform EditMode \
  -testResults Tests/edit-results.xml \
  -logFile - || exit 1

Unity -batchmode -projectPath . \
  -runTests -testPlatform PlayMode \
  -testResults Tests/play-results.xml \
  -logFile - || exit 1
```

Convert `*.xml` (NUnit format) to JUnit for GitHub/GitLab reports.

## Anti-patterns

| Anti-pattern | Fix |
|---|---|
| Tests sharing state via static fields | `[SetUp]` resets, or `[TearDown]` cleans |
| Real time-based assertions (`Thread.Sleep`) | Use `yield return new WaitForSeconds` in PlayMode |
| Loading actual scenes in EditMode | Refactor logic out of MonoBehaviour into POCOs you can unit test |
| One mega test method | Split into focused `[Test]` methods + `[TestCase]` data |

## Production checklist

- [ ] Test asmdefs flagged Test Assemblies
- [ ] EditMode covers all POCO logic
- [ ] PlayMode reserved for engine-dependent behaviour
- [ ] Performance baselines tracked in CI
- [ ] Tests run in CI on every PR
- [ ] Random seeds reproducible (fix `Random.InitState(seed)` in `[SetUp]`)

Wersje

RepozytoriumWynikLicencja
Ta strona · claude-dev-suite/claude-dev-suite100MIT
sheepk95/The-Cartographer100Apache-2.0
IdoCohen560/claude-unity-game-studio100MIT

Migawka bazy z 13.11.2026 · wersja paczki 83f8c33d9019 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100unity-tests-write
    Pisze testy Unity: EditMode, PlayMode, testy wydajności i pokrycie kodu.
  • 100unity-test-framework
    Pisze i uruchamia testy w Unity Test Framework: EditMode i PlayMode, atrybuty Test i UnityTest oraz konfigurację asmdef.
  • 95uloop-run-tests
    Uruchamia testy Unity Test Runner w trybach EditMode i PlayMode, opisuje szczegółowe wyniki oraz przyczyny błędów.
  • 95uloop-run-tests
    Uruchamia testy w Unity Test Runner w trybach EditMode i PlayMode i raportuje wyniki wraz z diagnozą nieudanych testów.
  • 88unity-batchmode
    Uruchamia Unity bez interfejsu: testy EditMode i PlayMode, budowanie gry przez skrypt z kodem wyjścia i sprawdzanie kompilacji, a także czyta logi.
  • 100testing-infrastructure
    Opisuje wzorce testów w Unity: UnitySystemTestBase, narzędzia ECS, mocki, tryby EditMode i PlayMode dla systemów ECS i kontrolerów.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.