gleam-testing
Guides Claude through testing Gleam applications with gleeunit. Use when writing unit tests, integration tests, or property-based tests. Always use let assert, NOT deprecated should module.
What this skill does
# Gleam Testing Skill
This skill guides Claude Code through testing Gleam applications.
## Primary Sources
1. **[Gleeunit Documentation](https://hexdocs.pm/gleeunit/)** - Test framework
2. **[Let Assert - Gleam Tour](https://tour.gleam.run/advanced-features/let-assert/)** - Assertion syntax
3. **[Testing Guide](https://abs0luty.github.io/gleam-tutorial/testing.html)** - Comprehensive testing
4. **[Test Timeouts](https://gearsco.de/blog/gleam-test-timeouts/)** - Timeout configuration
5. **[Birdie](https://hexdocs.pm/birdie/)** - Snapshot testing
6. **[Glacier](https://hexdocs.pm/glacier/)** - Interactive testing
7. **[QCheck](https://hexdocs.pm/gleam_qcheck/)** - Property-based testing
8. **[Gleamy Bench](https://hexdocs.pm/gleamy_bench/)** - Benchmarking
## Quick Reference
### Test Command
```bash
gleam test # Run all tests
gleam test --target erlang # Erlang target only
gleam test --target javascript # JavaScript target only
```
### Test File Structure
```
project/
├── test/
│ ├── project_name_test.gleam # Main test file
│ ├── feature_a_test.gleam # Feature tests
│ └── feature_b_test.gleam
```
## Critical Rules
### Use `let assert` NOT `should` (MANDATORY)
The `gleeunit/should` module is **deprecated**.
See examples: [Testing Practices](../../rules/testing-practices.md)
### Test Function Naming (MANDATORY)
Functions ending in `_test` are automatically discovered and run.
```gleam
pub fn my_feature_test() {
// Test implementation
}
```
See: [Gleeunit Documentation](https://hexdocs.pm/gleeunit/)
## Common Testing Patterns
### Unit Testing
```gleam
pub fn add_test() {
let assert 5 = add(2, 3)
let assert 0 = add(-1, 1)
}
```
### Testing Result Types
```gleam
pub fn parse_success_test() {
let assert Ok(value) = parse("valid input")
let assert expected_value = value
}
pub fn parse_failure_test() {
let assert Error(Nil) = parse("invalid input")
}
```
### Testing Custom Types
```gleam
pub fn user_creation_test() {
let user = create_user("[email protected]")
let assert Active(_, email) = user
let assert "[email protected]" = email
}
```
### Testing Error Variants
```gleam
pub fn error_handling_test() {
let assert Error(NotFound(id)) = fetch_user("invalid-id")
let assert "invalid-id" = id
}
```
## Advanced Testing
### Test Timeouts (Erlang Target)
For tests that need more than 5 seconds:
See: [Gleam Test Timeouts](https://gearsco.de/blog/gleam-test-timeouts/)
### Property-Based Testing
For testing properties that should hold for all inputs:
See: [gleam_qcheck Documentation](https://hexdocs.pm/gleam_qcheck/)
Example use cases:
- Testing that `reverse(reverse(list)) == list`
- Verifying encoding/decoding round-trips
- Checking mathematical properties
### Snapshot Testing
For testing rendered output:
See: [Birdie Documentation](https://hexdocs.pm/birdie/)
Use cases:
- HTML rendering
- JSON API responses
- Formatted text output
### Interactive Testing
For development workflows with fast feedback:
See: [Glacier Documentation](https://hexdocs.pm/glacier/)
## Testing Web Applications
### HTTP Request Testing
For Wisp applications:
See: [Wisp Testing](https://hexdocs.pm/wisp/)
### Database Testing
Patterns for testing with databases:
1. Use test databases
2. Wrap tests in transactions (rollback after)
3. Use fixtures for test data
4. Consider using SQLite in-memory for fast tests
### Mocking External Services
Gleam doesn't have built-in mocking. Patterns:
1. Dependency injection via function parameters
2. Test doubles (implement same type)
3. Behavior parameterization
## Testing OTP Applications
### Actor Testing
```gleam
import gleam/otp/actor
pub fn actor_behavior_test() {
let assert Ok(actor.Started(subject, _)) = start_my_actor()
// Test message handling
let response = actor.call(subject, waiting: 100, sending: fn(s) { GetState(s) })
let assert expected_state = response
}
```
See: [OTP Development](../skills/gleam-otp-development/SKILL.md)
### Supervision Testing
Test that supervisors:
- Start children correctly
- Restart children on failure
- Respect max restart limits
## Performance Testing
### Benchmarking
For performance measurements:
See: [gleamy_bench Documentation](https://hexdocs.pm/gleamy_bench/)
Use cases:
- Comparing algorithm implementations
- Measuring optimization impact
- Profiling hot code paths
## Test Organization
### Test Modules
Organize tests by feature or domain:
```
test/
├── auth_test.gleam # Authentication tests
├── user_test.gleam # User management
├── api_test.gleam # API endpoints
└── integration_test.gleam # Integration tests
```
### Test Helpers
Create helper functions in test modules:
```gleam
// test/test_helpers.gleam
pub fn create_test_user() -> User {
User(id: "test-id", email: "[email protected]")
}
pub fn with_database(test: fn(Connection) -> a) -> a {
let assert Ok(conn) = setup_test_db()
let result = test(conn)
teardown_test_db(conn)
result
}
```
## Cross-Platform Testing
Tests run on both Erlang and JavaScript targets by default. Be aware of platform differences:
- Test timeouts only work on Erlang
- Some external functions behave differently
- Platform-specific tests can use `@target` attribute
See: [External Functions](../../rules/external-functions.md)
## CI/CD Integration
### GitHub Actions
Example workflow:
```yaml
name: Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: "27.0"
gleam-version: "1.10.0"
- run: gleam deps download
- run: gleam test
- run: gleam format --check src test
```
See: [Writing Gleam - CI/CD](https://gleam.run/writing-gleam/)
## Test Coverage
Currently, Gleam doesn't have built-in coverage tools. Options:
1. Use Erlang's cover tool
2. Monitor test comprehensiveness manually
3. Focus on critical path coverage
## Common Testing Patterns
### Table-Driven Tests
```gleam
pub fn multiple_cases_test() {
let cases = [
#("input1", "output1"),
#("input2", "output2"),
#("input3", "output3"),
]
list.each(cases, fn(case) {
let #(input, expected) = case
let assert expected = my_function(input)
})
}
```
### Setup and Teardown
```gleam
pub fn test_with_setup() {
// Setup
let resource = create_resource()
// Test
let assert Ok(result) = use_resource(resource)
// Teardown (using defer-like pattern)
cleanup_resource(resource)
}
```
## Test Quality Guidelines
✅ **Good tests:**
- Test one thing
- Have clear names
- Are independent (no shared state)
- Are fast (when possible)
- Are deterministic
❌ **Avoid:**
- Testing implementation details
- Shared mutable state
- Flaky tests (timing-dependent)
- Tests that are hard to understand
---
**Remember**: Tests are documentation. Write them clearly and maintain them carefully.
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.