Agent skill

Add Unit Tests

by areal-project in areal-project/AReaL

Guide for adding unit tests to AReaL. An agent skill from areal-project/AReaL.

Apache-2.0Auto-check passedTesting & QA

Install Add Unit Tests

skills CLI
$ npx skills add areal-project/AReaL --skill add-unit-tests -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install areal-project/AReaL add-unit-tests --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/areal-project/AReaL.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/add-unit-tests .claude/skills/add-unit-tests && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
add-unit-tests
GitHub stars
5.8k
Token cost
~1.8k tokens
SKILL.md length
434 words
Files
1
Skills in repo
11
Repo updated
First seen
Licence
Apache-2.0

At a glance

Guide for adding unit tests to AReaL. An agent skill from areal-project/AReaL.

  • Works in 6 steps: Understand Test Types → Create Test File Structure → Write Test Functions → …
  • User wants to add tests for new functionality
  • SKILL.md covers When to Use, Step-by-Step Guide, Key Requirements (Based on… and Reference Implementations, plus 3 more sections
  • Calls uv, python and pytest

What it does

Add Unit Tests is an agent skill from areal-project/AReaL. Guide for adding unit tests to AReaL. Use when user wants to add tests for new functionality or increase test coverage.

Its SKILL.md is about 1.8k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Testing & QA, covering Unit testing and Test coverage. It works with pytest. The repository describes itself as: The RL Bridge for LLM-based Agent Applications. Made Simple & Flexible. The licence is Apache-2.0.

When your agent uses it

  • User wants to add tests for new functionality
  • Increase test coverage

Example prompts

  • “/add-unit-tests”

Requirements

  • Python 3

Workflow steps

6 steps, taken from the step headings in SKILL.md.

  1. Understand Test Types
  2. Create Test File Structure
  3. Write Test Functions
  4. Add Pytest Markers and CI Strategy
  5. Mock Distributed Environment
  6. Handle GPU Dependencies

What it can do on your machine

Read from SKILL.md and the folder at commit a642540. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • uv
    • python
    • pytest

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use uv, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Add Unit Tests loads about 1.8k tokens when it runs. Until then it costs about 34 tokens; SKILL.md has 434 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~34
When it runs · the whole SKILL.md, loaded when a task matches
~1.8k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from areal-project/AReaL at commit a642540, republished under its Apache-2.0 licence (© areal-project). 434 words, ~1,755 tokens.

Download SKILL.mdSave it as .claude/skills/add-unit-tests/SKILL.md (or your agent's skills folder).
name
add-unit-tests
description
Guide for adding unit tests to AReaL. Use when user wants to add tests for new functionality or increase test coverage.

Add Unit Tests

Add unit tests to AReaL following the project's testing conventions.

When to Use

This skill is triggered when:

  • User asks "how do I add tests?"
  • User wants to increase test coverage
  • User needs to write tests for new functionality
  • User wants to understand AReaL testing patterns

Step-by-Step Guide

Step 1: Understand Test Types

AReaL has two main test categories:

Test TypePurposeLocation PatternHow It Runs
Unit TestsTest individual functions/modulestests/test_<module>_<feature>.pyDirectly via pytest
Distributed TestsTest distributed/parallel behaviortests/torchrun/run_*.pyVia torchrun (called by pytest subprocess)

Note: All tests are invoked via pytest. Distributed tests use torchrun but are still called from pytest test files.

Step 2: Create Test File Structure

Create test file with naming convention: test_<module>_<feature>.py

python
import pytest
import torch

# Import the module to test
from areal.dataset.gsm8k import get_gsm8k_sft_dataset
from tests.utils import get_dataset_path  # Optional test utilities
# For mocking tokenizer: from unittest.mock import MagicMock
Step 3: Write Test Functions

Follow Arrange-Act-Assert pattern:

python
def test_function_under_condition_returns_expected():
    """Test that function returns expected value under condition."""
    # Arrange
    input_data = 5
    expected_output = 10

    # Act
    result = function_under_test(input_data)

    # Assert
    assert result == expected_output
Step 4: Add Pytest Markers and CI Strategy

Use appropriate pytest markers:

MarkerWhen to Use
@pytest.mark.slowTest takes > 10 seconds (excluded from CI by default)
@pytest.mark.ciSlow test that must run in CI (use with @pytest.mark.slow)
@pytest.mark.asyncioAsync test functions
@pytest.mark.skipif(cond, reason=...)Conditional skip
@pytest.mark.parametrize(...)Parameterized tests

CI Test Strategy:

  • @pytest.mark.slow: Excluded from CI by default (CI runs pytest -m "not slow")
  • @pytest.mark.slow + @pytest.mark.ci: Slow but must run in CI
  • No marker: Runs in CI (fast unit tests)
python
@pytest.mark.asyncio
async def test_async_function():
    result = await async_function()
    assert result == expected

@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available")
def test_gpu_feature():
    tensor = torch.tensor([1, 2, 3], device="cuda")
    # ... assertions

@pytest.mark.parametrize("batch_size", [1, 4, 16])
def test_with_parameters(batch_size):
    # Parameterized test

@pytest.mark.slow
def test_slow_function():
    # Excluded from CI by default

@pytest.mark.slow
@pytest.mark.ci
def test_slow_but_required_in_ci():
    # Slow but must run in CI
Step 5: Mock Distributed Environment

For unit tests that need distributed mocks:

python
import torch.distributed as dist

def test_distributed_function(monkeypatch):
    monkeypatch.setattr(dist, "get_rank", lambda: 0)
    monkeypatch.setattr(dist, "get_world_size", lambda: 2)
    result = distributed_function()
    assert result == expected
Step 6: Handle GPU Dependencies

Always skip gracefully when GPU unavailable:

python
CUDA_AVAILABLE = torch.cuda.is_available()

@pytest.mark.skipif(not CUDA_AVAILABLE, reason="CUDA not available")
def test_gpu_function():
    tensor = torch.tensor([1, 2, 3], device="cuda")
    # ... assertions

Key Requirements (Based on testing.md)

Mocking Distributed
  • Use torch.distributed.fake_pg for unit tests
  • Mock dist.get_rank() and dist.get_world_size() explicitly
  • Don't mock internals of FSDP/DTensor
Show full SKILL.md (179 more words)Show less
GPU Test Constraints
  • Always skip gracefully when GPU unavailable
  • Clean up GPU memory: torch.cuda.empty_cache() in fixtures
  • Use smallest possible model/batch for unit tests
Assertions
  • Use torch.testing.assert_close() for tensor comparison
  • Specify rtol/atol explicitly for numerical tests
  • Avoid bare assert tensor.equal() - no useful error message

Reference Implementations

Test FileDescriptionKey Patterns
tests/test_utils.pyUtility function testsFixtures, parametrized tests
tests/test_examples.pyIntegration tests with dataset loadingDataset path resolution, success pattern matching
tests/test_fsdp_engine_nccl.pyDistributed testsTorchrun integration

Common Mistakes

  • Missing test file registration: Ensure file follows test_*.py naming
  • GPU dependency without skip: Always use @pytest.mark.skipif for GPU tests
  • Incorrect tensor comparisons: Use torch.testing.assert_close() not assert tensor.equal()
  • Memory leaks in GPU tests: Clean up with torch.cuda.empty_cache()
  • Mocking too much: Don't mock FSDP/DTensor internals
  • Unclear test names: Follow test_<what>_<condition>_<expected> pattern
  • No docstrings: Add descriptive docstrings to test functions

Integration with Other Skills

This skill complements other AReaL development skills:

  • After /add-dataset: Add tests for new dataset loaders
  • After /add-workflow: Add tests for new workflows
  • After /add-reward: Add tests for new reward functions
  • With expert agents: Reference this skill when planning test implementation

Running Tests

bash
# First check GPU availability (many tests require GPU)
python -c "import torch; print('GPU available:', torch.cuda.is_available())"

# Run specific test file
uv run pytest tests/test_<name>.py

# Skip slow tests (CI default)
uv run pytest -m "not slow"

# Run with verbose output
uv run pytest -v

# Run distributed tests (requires torchrun and multi-GPU)
# Note: Usually invoked via pytest test files
torchrun --nproc_per_node=2 tests/torchrun/run_<test>.py

© areal-project, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/add-unit-tests of areal-project/AReaL.

Open the folder on GitHubat commit a642540

Compare with similar skills

Add Unit Tests next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Add Unit Tests compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Add Unit Tests this skillareal-project/AReaL5.8k—~1.8kAutomated safety check: PassApache-2.0
Test Coverage Reviewareed1192/finance-news-aggregator149—~2.6kAutomated safety check: PassMIT
NIC Testing Patternsnginx/kubernetes-ingress5.1k—~2.8kAutomated safety check: PassApache-2.0
Squid Testing Pythoniusztinpaul/squid203—~1.3kAutomated safety check: PassApache-2.0
Mutation Test Strength Auditbuildfastwithai/gen-ai-experiments785—~641Automated safety check: PassMIT
TDD Guidealirezarezvani/claude-skills28k—~3.4kAutomated safety check: PassMIT

Similar skills

  • Test Coverage Review

    areed1192/finance-news-aggregator

    Audit, plan, write, and verify unit tests for Python projects using pytest.

    149 GitHub stars~2.6k tokensUpdated 5 mo ago
    Testing & QAAuto-check passed
  • NIC Testing Patterns

    nginx/kubernetes-ingress

    Testing conventions for the NGINX Ingress Controller repo: Go table-driven tests, mandatory snapshot regeneration, Helm tests and Python pytest integration tests.

    5.1k GitHub stars~2.8k tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Squid Testing Python

    iusztinpaul/squid

    Write and evaluate effective Python tests using pytest. An agent skill from iusztinpaul/squid.

    203 GitHub stars~1.3k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • Mutation Test Strength Audit

    buildfastwithai/gen-ai-experiments

    Measures how well a Python pytest suite catches behavior changes through diff-scoped mutation testing, then proposes and verifies tests for surviving mutants.

    785 GitHub stars~641 tokensUpdated 16 days ago
    Testing & QAAuto-check passed
  • TDD Guide

    alirezarezvani/claude-skills

    Test-driven development skill for writing unit tests, generating test fixtures and mocks, analyzing coverage gaps, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, Vitest, and…

    28k GitHub stars~3.4k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • TDD Guide

    LeoYeAI/openclaw-master-skills

    Test-driven development skill for writing unit tests, generating test fixtures and mocks, analyzing coverage gaps, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, Vitest, and…

    2.2k GitHub stars~1.4k tokensUpdated 2 mo ago
    Testing & QAAuto-check passed

More from areal-project/AReaL

All 11 skills in this repo
  • Add Dataset

    areal-project/AReaL

    Guide for adding a new dataset loader to AReaL. An agent skill from areal-project/AReaL.

    5.8k GitHub starsUsed in 1 repo~1.4k tokens
    Auto-check passed
  • Add Reward

    areal-project/AReaL

    Guide for adding a new reward function to AReaL. An agent skill from areal-project/AReaL.

    5.8k GitHub starsUsed in 1 repo~1.2k tokens
    Auto-check passed
  • Debug Distributed

    areal-project/AReaL

    Guide for debugging distributed training issues in AReaL. An agent skill from areal-project/AReaL.

    5.8k GitHub starsUsed in 1 repo~1.6k tokens
    Auto-check passed
  • Add Archon Model

    areal-project/AReaL

    Guide for adding a new model to the Archon engine. An agent skill from areal-project/AReaL.

    5.8k GitHub stars~4.9k tokensUpdated yesterday
    Auto-check passed
  • Add Workflow

    areal-project/AReaL

    Guide for adding a new RolloutWorkflow to AReaL. An agent skill from areal-project/AReaL.

    5.8k GitHub stars~1.1k tokensUpdated yesterday
    Auto-check passed
  • Review PR

    areal-project/AReaL

    Read-only pull request review workflow with risk analysis, targeted checklists, and Codex subagent consultation.

    5.8k GitHub stars~704 tokensUpdated yesterday
    Auto-check passed

Works with

Categories

Questions about Add Unit Tests

What does Add Unit Tests do?

Guide for adding unit tests to AReaL. An agent skill from areal-project/AReaL. Add Unit Tests is an agent skill from areal-project/AReaL. Guide for adding unit tests to AReaL.

When should I use Add Unit Tests?

Add Unit Tests fits situations like: user wants to add tests for new functionality; increase test coverage.

How do I install Add Unit Tests in Claude Code?

Run `npx skills add areal-project/AReaL --skill add-unit-tests -a claude-code`. Or copy the skill folder (.agents/skills/add-unit-tests in areal-project/AReaL) into .claude/skills/add-unit-tests in your project. Claude Code loads it when a task matches its description.

How do I install Add Unit Tests in Codex?

Run `npx skills add areal-project/AReaL --skill add-unit-tests -a codex`. Or copy the skill folder (.agents/skills/add-unit-tests in areal-project/AReaL) into .agents/skills/add-unit-tests in your project. Codex loads it when a task matches its description.

Can I use Add Unit Tests in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add areal-project/AReaL --skill add-unit-tests -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/add-unit-tests, .gemini/skills/add-unit-tests, .github/skills/add-unit-tests and .opencode/skills/add-unit-tests in your project.

What does Add Unit Tests need to run?

Going by SKILL.md and its folder, Add Unit Tests needs the command-line tools its instructions call (uv, python and pytest). Our summary lists: Python 3.

Does Add Unit Tests access the network?

SKILL.md contains no URLs. Its commands use uv, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Add Unit Tests safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Add Unit Tests use?

Add Unit Tests is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Add Unit Tests use?

About 1.8k tokens (SKILL.md is roughly 7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Add Unit Tests?

Skills that share tags, products or a category with Add Unit Tests: Test Coverage Review (areed1192/finance-news-aggregator, 149 stars), NIC Testing Patterns (nginx/kubernetes-ingress, 5.1k stars), Squid Testing Python (iusztinpaul/squid, 203 stars) and Mutation Test Strength Audit (buildfastwithai/gen-ai-experiments, 785 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Add Unit Tests?

areal-project (a GitHub organization) maintains it in areal-project/AReaL, which has 5,817 GitHub stars. The repository holds 11 skills in this directory. The repository was last updated on October 8, 2026.

Source: areal-project/AReaL on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.