Skills Unit Testing
After writing a Skill, how do you confirm it really works as expected? Manual testing is time-consuming and prone to omissions.
This article explains how to build systematic test cases for a Skill, from script unit tests to end-to-end trigger tests.
Two levels of Skill testing
| Level | Test target | Method |
|---|---|---|
| Script unit testing | Python/JS scripts under scripts/ | pytest / standard unittest |
| Trigger end-to-end testing | Whether the Skill is triggered correctly and whether the output meets expectations | skill-creator's eval framework |
Level one: Script unit testing
Scripts are the most deterministic part of a Skill, suitable for coverage with standard unit testing frameworks.
Example
File path: scripts/tests/test_clean_data.py
import
pytest
import
os
import
tempfile
import
csv
Module under test
import
sys
sys
.
path
.
insert
(
0
,
os
.
path
.
join
(
os
.
path
.
dirname
(
file
)
,
".."
)
)
from
clean_data
import
remove_duplicates
,
fill_nulls
,
strip_whitespace
── Test: Deduplication ──────────────────────────────────────────
def
test_remove_duplicates_basic
(
)
:
"""Normal case: duplicate lines should be removed"""
rows
=
[
{
"name"
:
"runoob"
,
"score"
:
"90"
}
,
{
"name"
:
"runoob"
,
"score"
:
"90"
}
,
Duplicate rows
{
"name"
:
"RUNOOB"
,
"score"
:
"80"
}
,
]
result
=
remove_duplicates
(
rows
)
assert
len
(
result
)
==
2
,
"1 duplicate line should be removed"
def
test_remove_duplicates_empty
(
)
:
"""Edge case: an empty list should not raise an error"""
result
=
remove_duplicates
(
[
]
)
assert
result
==
[
]
── Test: Empty value filling ──────────────────────────────────────
def
test_fill_nulls_numeric
(
)
:
"""Empty values in numeric columns should be filled with 0"""
rows
=
[
{
"value"
:
"10"
}
,
{
"value"
:
""
}
,
{
"value"
:
"20"
}
]
result
=
fill_nulls
(
rows
,
col
=
"value"
,
fill_with
=
"0"
)
assert
result
[
1
]
[
"value"
]
==
"0"
── Test: Whitespace removal ──────────────────────────────────────
def
test_strip_whitespace
(
)
:
"""Leading and trailing spaces in strings should be stripped"""
rows
=
[
{
"name"
:
" runoob "
}
,
{
"name"
:
"RUNOOB"
}
]
result
=
strip_whitespace
(
rows
,
col
=
"name"
)
assert
result
[
0
]
[
"name"
]
==
"runoob"
assert
result
[
1
]
[
"name"
]
==
"RUNOOB"
── Integration test: Reading a real file ──────────────────────────────
def
test_process_real_file
(
)
:
"""Create a temporary CSV file and test the complete processing flow"""
with
tempfile
.
NamedTemporaryFile
(
mode
=
"w"
,
suffix
=
".csv"
,
delete
=
False
,
newline
=
""
)
as
f:
writer
=
csv
.
DictWriter
(
f
,
fieldnames
=
[
"name"
,
"score"
]
)
writer.
writeheader
(
)
writer.
writerow
(
{
"name"
:
" runoob "
,
"score"
:
"90"
}
)
writer.
writerow
(
{
"name"
:
" runoob "
,
"score"
:
"90"
}
)
Repeat
writer.
writerow
(
{
"name"
:
"RUNOOB"
,
"score"
:
""
}
)
Empty values
tmp_path
=
f.
name
try
:
from
clean_data
import
process_file
result
=
process_file
(
tmp_path
)
assert
result
[
"removed_rows"
]
==
1
assert
result
[
"fixed_values"
]
==
1
finally
:
os
.
unlink
(
tmp_path
)
Run the tests:
# Run all tests after entering the Skill directory
cd my-skill/
pytest scripts/tests/ -v
# Generate coverage report
pytest scripts/tests/ --cov=scripts --cov-report=term-missing
Output:
scripts/tests/test_clean_data.py::test_remove_duplicates_basic PASSED
scripts/tests/test_clean_data.py::test_remove_duplicates_empty PASSED
scripts/tests/test_clean_data.py::test_fill_nulls_numeric PASSED
scripts/tests/test_clean_data.py::test_strip_whitespace PASSED
scripts/tests/test_clean_data.py::test_process_real_file PASSED
5 passed in 0.12s
Level two: Trigger end-to-end testing
Trigger testing verifies whether Claude uses this Skill when a user makes a certain request.
Test cases are defined in JSON format, containing the user prompt and expected behavior assertions.
Example
[
{
"id"
:
"trigger_basic"
,
"prompt"
:
"Help me analyze this sales data CSV, find monthly trends, and generate a statistical summary"
,
"assertions"
:
[
{
"type"
:
"skill_triggered"
,
"skill"
:
"csv-analyzer"
,
"description"
:
"Complex analysis requests should trigger csv-analyzer"
}
]
}
,
{
"id"
:
"trigger_with_file"
,
"prompt"
:
"I uploaded runoob_sales.csv, please analyze the data distribution of each column"
,
"assertions"
:
[
{
"type"
:
"skill_triggered"
,
"skill"
:
"csv-analyzer"
}
,
{
"type"
:
"output_contains"
,
"keyword"
:
"Statistics"
,
"description"
:
"The output should contain statistical information"
}
]
}
,
{
"id"
:
"no_trigger_simple"
,
"prompt"
:
"What format is CSV?"
,
"assertions"
:
[
{
"type"
:
"skill_not_triggered"
,
"skill"
:
"csv-analyzer"
,
"description"
:
"Simple knowledge questions should not trigger the Skill"
}
]
}
]
Run trigger tests (requires the eval tool provided by skill-creator):
Example
Run the test set and generate a visual report
python
-m
scripts.run_eval \
--eval-set
evals
/
trigger-eval.json \
--skill-path
csv-analyzer
/
\
--model
claude-sonnet-
4
20250514
Generate an HTML report for manual review
python eval-viewer
/
generate_review.py \
--results
evals
/
results
/
\
--output
evals
/
review.html
The prompts in test cases should be complex enough; even if a simple "read CSV" type of request fails to trigger, it doesn't mean the Skill has a problem, because Claude can handle it itself. Good test cases should be multi-step requests with clear output requirements that real users would actually make.
Coverage of test cases
| Type | Scenarios to cover |
|---|---|
| Positive triggering | Complex tasks, containing keywords, explicit output format requirements |
| Negative triggering | Simple Q&A, merely mentioning related words without needing the Skill |
| Boundary inputs | Empty files, oversized files, files in unsupported formats |
| Error recovery | Whether the error message is clear when a file path is wrong |