Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

testing

/testing

Pisze lub naprawia testy w Elixirze z ExUnit, sandboxem, Mox, ExMachina i LiveViewTest, także niestabilne testy.

Licencja
MIT
Ostatnia zmiana repozytorium
22.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
5
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 22.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

Pisze lub naprawia testy w Elixirze z ExUnit, sandboxem, Mox, ExMachina i LiveViewTest, także niestabilne testy.

Oryginalny opis (EN)

Write or repair Elixir tests with ExUnit, sandbox isolation, async reliability, Mox, ExMachina, and LiveViewTest. Use for test files, test setup, or failing/flaky tests. NOT for investigating an application bug outside the test suite.

Jak działa

  1. Iron Laws — Never Violate These
  2. Quick Decisions
  3. Quick Patterns
  4. Common Anti-patterns
  5. References
Sekcje z nagłówków SKILL.md, w oryginale · 84 linii, 394 słów
Podgląd SKILL.md
---
name: testing
description: "Write or repair Elixir tests with ExUnit, sandbox isolation, async reliability, Mox, ExMachina, and LiveViewTest. Use for test files, test setup, or failing/flaky tests. NOT for investigating an application bug outside the test suite."
effort: medium
user-invocable: false
paths:
  - "test/**/*_test.exs"
  - "test/support/**/*.ex"
  - "**/*factory*.ex"
---

# Elixir Testing Reference

> **Ash projects**: Use `DataCase` with `Ash.Test` helpers; test actions via domain code interfaces, not direct `Repo` calls. See `ash-framework` skill.

Quick reference for Elixir testing patterns.

## Iron Laws — Never Violate These

1. **ASYNC BY DEFAULT** — Use `async: true` unless tests modify global state
2. **SANDBOX ISOLATION** — All database tests use Ecto.Adapters.SQL.Sandbox
3. **MOCK ONLY AT BOUNDARIES** — Never mock database, internal modules, or stdlib
4. **BEHAVIOURS AS CONTRACTS** — All mocks must implement a defined `@callback` behaviour
5. **BUILD BY DEFAULT** — Use `build/2` in factories; `insert/2` only when DB needed
6. **NO PROCESS.SLEEP** — Use `assert_receive` with timeout for async operations
7. **VERIFY_ON_EXIT!** — Always call in Mox tests setup
8. **FACTORIES MATCH SCHEMA REQUIRED FIELDS** — Factory definitions must include all fields that have `validate_required` in the schema changeset. Missing fields cause cascading test failures

## Quick Decisions

### Which Test Case?

| Testing | Use |
|---------|-----|
| Controller/API | `use MyAppWeb.ConnCase` |
| Context/Schema | `use MyApp.DataCase` |
| LiveView | `use MyAppWeb.ConnCase` + `import Phoenix.LiveViewTest` |
| Pure logic | `use ExUnit.Case, async: true` |

### When to use async: true?

- ✅ Pure functions, no shared state
- ✅ Database tests with Sandbox (PostgreSQL)
- ❌ Tests modifying `Application.put_env`
- ❌ Tests using Mox global mode

### Mock or not?

- ✅ Mock: External APIs, email services, file storage
- ❌ Don't mock: Database, internal modules, stdlib

### build() or insert()?

- Use `build()` by default for speed
- Use `insert()` only when you need DB ID, constraints, or persisted associations

## Quick Patterns

```elixir
# Setup chain
setup [:create_user, :authenticate]

# Pattern matching assertion
assert {:ok, %User{name: name}} = create_user(attrs)

# Async message assertion
assert_receive {:user_created, _}, 5000

# Mox setup
setup :verify_on_exit!
expect(MockAPI, :call, fn _ -> {:ok, "data"} end)

# LiveView async
html = render_async(view)  # MUST call for assign_async
```

## Common Anti-patterns

| Wrong | Right |
|-------|-------|
| `Process.sleep(100)` | `assert_receive {:done, _}, 5000` |
| `insert(:user)` in factory | `build(:user)` in factory |
| `async: true` with `set_mox_global()` | `async: false` |
| Mock internal modules | Test through public API |

## References

For detailed patterns, see:

- `${CLAUDE_SKILL_DIR}/references/exunit-patterns.md` - Setup, assertions, tags
- `${CLAUDE_SKILL_DIR}/references/mox-patterns.md` - Behaviours, expect/stub, async
- `${CLAUDE_SKILL_DIR}/references/liveview-testing.md` - Forms, async, uploads
- `${CLAUDE_SKILL_DIR}/references/factory-patterns.md` - ExMachina, sequences, traits
Pliki w paczce (5)
  • SKILL.md 3 KB
  • references/exunit-patterns.md 5 KB
  • references/factory-patterns.md 3 KB
  • references/liveview-testing.md 2 KB
  • references/mox-patterns.md 2 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · oliver-kriska/claude-elixir-phoenix100MIT
iuliandita/skills100MIT
wrongstack/wrongstack100MIT
langwatch/langwatch100Apache-2.0
mcouthon/agents100MIT
nteract/nteract100BSD-3-Clause
kettleofketchup/DraftForge100GPL-3.0
skillberry-ai/cap-evolve100Apache-2.0
TheBeardedBearSAS/claude-craft100MIT

Migawka bazy z 13.11.2026 · wersja paczki b6c540b81e19 (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

  • 90estack-testing
    Testuje zachowanie Elixir i Phoenix przez ExUnit, sandbox Ecto, atrapy, Mox i LiveViewTest, z izolacją wywołań zewnętrznych.
  • 100testing-essentials
    Pisze lub naprawia testy ExUnit: DataCase i ConnCase, fixtury, helpery LiveView, uploady, stuby Mox i Req, zasady async i sandboxa.
  • 90exunit-code-review
    Przegląda testy ExUnit pod kątem właściwych wzorców, mockowania granic przez Mox i użycia adapterów testowych, w plikach _test.exs i konfiguracji test helperów.
  • 100elixir-test-critic
    Ocenia jakość testów Elixir i ExUnit przy przeglądzie plików testowych, audycie zestawów testów i pisaniu nowych testów według dobrych praktyk.
  • 100v1-e2e-testing
    Pisze i naprawia testy end-to-end w przeglądarce, zwłaszcza w Playwright, i diagnozuje niestabilne testy.
  • 100bifrost-testing
    Pisze i uruchamia testy Bifrost dla komponentów, stron i funkcji, a także diagnozuje testy niestabilne.

Uwagi i zgłoszenia

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