All skills
lexler avatar

/approval-tests

@83aee6a
by Lada Kesselerlexler/skill-factory238 stars
61

Writes approval tests (snapshot/golden master testing) for Python, JavaScript/TypeScript, or Java. Use when verifying complex output, characterization testing legacy code, testing combinations, or working with .approved/.received files.

Use this Skill: https://skilld.dev/gh/lexler/skill-factory/approval-tests

This session only. Nothing lands on disk.

java.md

≈921 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Java ApprovalTests

Installation

Look up latest version at https://mvnrepository.com/artifact/com.approvaltests/approvaltests

Maven

<dependency>
    <groupId>com.approvaltests</groupId>
    <artifactId>approvaltests</artifactId>
    <version>VERSION</version>
    <scope>test</scope>
</dependency>

Gradle

testImplementation 'com.approvaltests:approvaltests:VERSION'

Quick Start

import org.approvaltests.Approvals;
import org.junit.jupiter.api.Test;

class ReportTest {
    @Test
    void generatesReport() {
        String result = generateReport();
        Approvals.verify(result);
    }
}

First run: Test fails, .received file created. Review it, approve it (copy to .approved), rerun.

Common Imports

import org.approvaltests.Approvals;
import org.approvaltests.JsonApprovals;
import org.approvaltests.combinations.CombinationApprovals;
import org.approvaltests.core.Options;
import org.approvaltests.scrubbers.DateScrubber;

Core Patterns

Approvals.verify() - Basic verification

Approvals.verify(result);
Approvals.verify(object.toString());

JsonApprovals.verifyAsJson() - Objects as formatted JSON

JsonApprovals.verifyAsJson(user);

Approvals.verifyAll() - Collections with labels

Approvals.verifyAll("Users", users, u -> u.getName() + ": " + u.getEmail());

Scrubbing

Options options = new Options()
    .withScrubber(DateScrubber.getScrubberFor("00:00:00"));
Approvals.verify(result, options);

Combinations

CombinationApprovals.verifyAllCombinations(
    (size, color) -> createProduct(size, color),
    new String[]{"S", "M", "L"},
    new String[]{"red", "blue"}
);

Java-Specific Notes

@UseReporter annotation sets reporter at class level:

@UseReporter(Junit5Reporter.class)
public class MyTest { }

JUnit 5 recommended. Use Junit5Reporter.

Java 8+ required for formatter lambdas.

Git Setup

*.received.*

Commit all .approved.* files.

Quick Decision Guide

  • Objects → JsonApprovals.verifyAsJson(obj)
  • Arrays/lists (structured) → JsonApprovals.verifyAsJson(items)
  • Arrays/lists (labeled) → Approvals.verifyAll("Items", items, formatter)
  • Non-deterministic data → scrubbers, add before first run (scrubbers.md)
  • Multiple scenarios per test → NamerFactory.withParameters() (advanced.md)
  • Input combinations → CombinationApprovals.verifyAllCombinations() (or verifyBestCoveringPairs for huge sets) (api.md)
  • State progressions → StoryBoard (api.md)
  • Console output → ConsoleOutput (logging.md)
  • Short inline expectations → Options().inline(expected) (inline.md)

Reference Files

  • api.md - verifyXml/Html, CombinationApprovals, StoryBoard, Verifiable interface, database results
  • scrubbers.md - DateScrubber formats, GuidScrubber, RegExScrubber, combining scrubbers
  • reporters.md - IDE/diff tool reporters, FirstWorkingReporter, custom reporters
  • setup.md - JUnit 4/5 setup, dynamic tests, Kotlin support
  • inline.md - Text blocks for inline approvals, InlineOptions modes
  • logging.md - ConsoleOutput for System.out/err verification
  • advanced.md - NamerFactory, PackageSettings, OS/machine-specific tests, common mistakes

Source: SKILL.md on GitHub

1 warning6d4 checks · Risk SAFE
  • Gen Agent Trust Hub6d

    The skill provides instructions and patterns for implementing approval testing (snapshot testing) across multiple programming languages. It includes capabilities for file system operations, command execution for testing CLI tools, and launching external diff reporters, which are consistent with the skill's purpose. The analysis identified an indirect prompt injection surface when verifying external or untrusted data.

  • Socket6d

    No alerts

  • Snyk6d

    Risk: LOW · No issues

  • Runlayer7mo

    25/25 files flagged

Signed by skilld at 83aee6a. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 8 months ago

README badge

README badge for lexler/skill-factory/approval-tests