/test

Development L2+ Production high usage

/test

Overview

/test is a production command in the Development category of the Prismatic Platform. It provides comprehensive test generation, execution, and verification across the entire umbrella codebase, covering unit tests, integration tests, property-based tests, and contract tests. The command analyzes source code to identify testable behaviors, generates ExUnit test modules with appropriate assertions, executes test suites with configurable scope, and reports results with coverage metrics. It is one of the highest-usage commands in the platform, integral to the NO MERCY doctrine requirement of 100% test coverage.

This command operates under the L2+ authority level and is executed by the testing-specialist agent. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The testing-specialist agent has deep knowledge of ExUnit conventions, property-based testing with StreamData, LiveView testing patterns, Ecto test sandboxing, and the platform's 121-test three-phase test architecture (Phase 1: Workflow/Step, Phase 2: Storage/Web/Agent, Phase 3: E2E).

The platform maintains 5,864 test files across 90+ umbrella applications. /test manages this test estate: generating new tests for uncovered code, running targeted test suites for modified modules, verifying test quality (assertions per test, edge case coverage, determinism), and enforcing the platform's mandatory regression test protocol. Every bug fix produced by /fix is validated through /test-generated regression tests.

Architecture

The test system operates as a three-stage pipeline: analysis, generation, and execution.

Test Architecture

             /test
                |
          Test Orchestrator
                |
          +-----+-----+-----+
          |     |     |     |
       Analyze Generate  Execute
       Module  Module    Module
          |     |     |
    +-----+-+ +-+-+ +-+-----+
    |   |   | | | | |   |   |
   Func Spec Edge Unit Prop Integ
   Scan  Ext  Case Gen  Gen  Gen
    |   |   | | | | |   |   |
    +---+---+-+-+-+-+---+---+
                |
          Execution Engine
                |
          +-----+-----+-----+
          |     |     |     |
       ExUnit  Cover  Report
       Runner  Tracker Generator

Test Categories

CategoryGeneratorAssertion StyleCoverage Target
Unit TestsFunction analysisassert/refute on return valuesAll public functions
Property Tests@spec type analysisStreamData generators, check allComplex logic
Integration TestsModule interactionMulti-module scenariosModule boundaries
Contract TestsBehaviour/ProtocolAdapter contract assertionsAll implementations
LiveView TestsRoute + LiveViewrender, live, elementAll LiveView pages
Controller TestsRouter analysisconn pipeline assertionsAll routes
Regression TestsBug analysisSpecific failure reproductionAll bug fixes

Three-Phase Test Architecture

PhaseTest CountScopePurpose
Phase 136Workflow + StepCore pipeline correctness
Phase 241Storage + Web + AgentIntegration layer validation
Phase 344End-to-EndFull system verification

Usage

# Run all tests
/test

# Run tests for specific application
/test --app prismatic_web

# Generate tests for specific module
/test --generate PrismaticPerimeter.SecurityRating

# Run tests for recently modified files
/test --changed

# Run tests with coverage reporting
/test --coverage

# Generate property-based tests
/test --property PrismaticStorage.ETS.Adapter

# Run specific test file
/test --file apps/prismatic_web/test/prismatic_web/live/perimeter_live_test.exs

# Generate regression test for a bug
/test --regression "nil access in SecurityRating.calculate/1"

# Run tests matching a tag
/test --tag integration

# Show test statistics
/test --stats

# Run tests in watch mode
/test --watch

Practical Examples

# Pre-commit test verification
/test --changed --coverage --fail-under 80

# Generate comprehensive tests for new module
/test --generate PrismaticPerimeter.AssetDiscovery --include-property --include-integration

# Run LiveView-specific tests
/test --app prismatic_web --tag liveview --verbose

# Contract test verification for all storage adapters
/test --tag contract --verbose

# Generate and run regression test for specific bug
/test --regression "empty list crash in ComplianceAssessment.assess/2" --verify

# Full platform test suite with timing analysis
/test --all --timing --slow-threshold 500ms

# CI mode with strict coverage and JUnit output
/test --all --coverage --fail-under 85 --format junit --export ./test-results/

Options

OptionTypeDefaultDescription
--appstringallSpecific application to test
--filepathnoneSpecific test file to run
--generatestringnoneModule to generate tests for
--regressionstringnoneBug description for regression test generation
--changedflagfalseTest only recently modified files
--coverageflagfalseInclude coverage reporting
--fail-underinteger0Minimum coverage percentage (CI mode)
--propertystringnoneGenerate property-based tests for module
--tagstringnoneRun tests matching tag
--exclude-tagstringnoneExclude tests matching tag
--verboseflagfalseDetailed test output
--watchflagfalseRe-run tests on file changes
--timingflagfalseShow test execution timing
--slow-thresholdduration1sThreshold for marking tests as slow
--formatenumtextOutput format: text, json, junit
--exportpathnoneExport results to file
--allflagfalseRun complete test suite across all apps
--seedintegerrandomExUnit random seed for reproducibility
--include-propertyflagfalseInclude property tests in generation
--include-integrationflagfalseInclude integration tests in generation
--verifyflagfalseVerify generated tests pass
--statsflagfalseShow test suite statistics

Execution Flow

Phase 1: Test Scope Resolution

Based on options, the test scope is determined. For --changed, Git diff identifies modified source files and their corresponding test files. For --app, all tests within the application are selected. For --generate, the target module is analyzed to determine what tests are needed.

Phase 2: Test Generation (when applicable)

For --generate and --regression modes, the testing-specialist analyzes the target module. Public functions are extracted with their @spec types. Edge cases are identified from guard clauses, pattern matching, and conditional branches. Test modules are generated with appropriate setup, test cases, and assertions. Property tests use StreamData generators derived from @spec types.

Phase 3: Test Execution

Tests are executed through ExUnit with configured options. For umbrella applications, tests run with --warnings-as-errors to catch runtime issues. Ecto tests use the SQL sandbox for database isolation. LiveView tests use the test endpoint configuration. Coverage tracking is enabled via mix test --cover.

Phase 4: Result Analysis

Test results are analyzed for: pass/fail counts, test duration distribution, coverage metrics by module and line, slow tests exceeding threshold, and flaky test detection (when --seed is varied). Generated tests are validated against the target module to ensure adequate coverage.

Phase 5: Report Generation

Results are formatted according to the requested output. The report includes: test suite summary, failure details with stack traces, coverage report with uncovered lines, timing analysis for slow tests, and recommendations for additional test coverage.

Integration Points

ComponentIntegration TypeDescription
/codePeerCode implementation paired with test generation
/fixUpstreamBug fixes require regression tests from /test
/svihadloUpstreamRapid features include auto-generated tests
/quality-gatesEnforcementTest passage is a quality gate requirement
/regression-checkPeerRegression checks validate test adequacy
/refactorValidationRefactoring verified by existing tests
Quality DNAStateTest metrics persisted in quality DNA
TelemetryMonitoringTest execution metrics and trends

Best Practices

Test-Driven Development

Use /test --generate before writing implementation code to establish expected behavior. Generated test skeletons define the contract that the implementation must satisfy. This approach produces cleaner interfaces and higher-quality implementations.

Regression Test Discipline

Every bug fix must include a regression test. Use /test --regression to generate tests that reproduce the specific failure condition. The mandatory regression test protocol requires: test fails before fix, test passes after fix, test is committed with the fix.

Coverage Monitoring

Run /test --coverage --fail-under 80 in CI pipelines to prevent coverage degradation. For critical modules (security, authentication, data access), target 95%+ coverage. Use /test --stats to identify modules with declining coverage.

Property-Based Testing for Complex Logic

For functions with complex input domains (parsers, validators, scoring algorithms), generate property-based tests with /test --property. StreamData generators explore input spaces more thoroughly than hand-written test cases, catching edge cases that example-based tests miss.

Error Handling

Error CodeDescriptionResolution
COMPILATION_FAILURETest file fails to compileCheck test file for syntax errors
SANDBOX_TIMEOUTEcto sandbox checkout timed outIncrease sandbox timeout or check for long-running transactions
FLAKY_DETECTEDTest produces inconsistent resultsInvestigate non-deterministic behavior; add --seed for debugging
COVERAGE_BELOW_THRESHOLDCoverage below --fail-under valueAdd tests for uncovered modules
GENERATION_FAILURECannot generate tests for moduleCheck module has public functions with @spec
REGRESSION_INCOMPLETERegression test does not reproduce bugRefine bug description for more precise test
TEST_TIMEOUTIndividual test exceeded timeoutCheck for infinite loops or slow external calls

Advanced Usage

Mutation Testing

Verify test quality through mutation testing:

/test --mutation PrismaticPerimeter.SecurityRating --verbose

Test Parallelism Optimization

Optimize test execution for CI:

/test --all --max-parallel 8 --partition 1/4 --format junit --export ./results/

Snapshot Testing

Generate snapshot tests for complex output:

/test --snapshot PrismaticPerimeter.ComplianceReport.generate/1 --format json

Doctrine Compliance

All commands operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Zero tolerance for incomplete execution or quality violations. 100% test coverage is the standard. No untested code, no stubs, no mocks, no placeholders.
  • NO DOUBTS: Full investigation before action, evidence-based results. Every test assertion is grounded in specification or observed behavior. Test generation is based on actual code analysis, not template guessing.
  • /code - Core coding implementation and feature development
  • /fix - Bug fix implementation with mandatory regression tests
  • /refactor - Safe refactoring with zero-regression guarantee
  • /svihadlo - Ultra-fast visible feature implementation in 5-15 minutes
  • /quality-gates - Enforce quality gate checkpoints with zero-warning compilation validation
  • /regression-check - Execute 25 custom Credo regression checks preventing 700+ violations
  • /validate - Input validation and data integrity enforcement

Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL