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.

referencesjavalogging.md

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

Java Console Output Verification

Capture and verify console output and error streams.

Contents

ConsoleOutput

Basic Usage

import org.approvaltests.utils.ConsoleOutput;
import org.junit.jupiter.api.Test;

@Test
void testConsoleOutput() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        System.out.println("Hello, World!");
        System.out.println("Processing complete");
        console.verifyOutput();
    }
}

ConsoleOutput captures everything written to System.out and System.err within the try-with-resources block.

Verify Standard Output

@Test
void testStdOut() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        runProcessThatPrints();
        console.verifyOutput();
    }
}

Verify Error Output

@Test
void testStdErr() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        runProcessThatLogsErrors();
        console.verifyError();
    }
}

Verify Both Streams

@Test
void testBothStreams() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        System.out.println("Standard output");
        System.err.println("Error output");
        console.verifyAll();
    }
}

Output format:

Output:
Standard output

Error:
Error output

With Options

Scrubbing Console Output

@Test
void testWithScrubbing() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        System.out.println("Process started at 10:30:00");
        System.out.println("Completed successfully");

        Options options = new Options()
            .withScrubber(DateScrubber.getScrubberFor("00:00:00"));
        console.verifyOutput(options);
    }
}

Inline Approvals

@Test
void testInlineConsole() {
    var expected = """
        Hello, World!
        Processing complete
        """;
    try (ConsoleOutput console = new ConsoleOutput()) {
        System.out.println("Hello, World!");
        System.out.println("Processing complete");
        console.verifyOutput(new Options().inline(expected));
    }
}

Getting Raw Output

For custom processing before verification:

@Test
void testRawAccess() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        runProcess();

        String output = console.getOutput();
        String errors = console.getError();

        // Custom processing
        String filtered = filterNoise(output);
        Approvals.verify(filtered);
    }
}

Common Patterns

Testing CLI Output

@Test
void testCliApplication() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        MyCliApp.main(new String[]{"--help"});
        console.verifyOutput();
    }
}

Testing Logging Libraries

When your code uses System.out or System.err directly:

@Test
void testLegacyLogging() {
    try (ConsoleOutput console = new ConsoleOutput()) {
        LegacyService service = new LegacyService();
        service.processWithLogging(data);
        console.verifyAll();
    }
}

Combining with Return Value

@Test
void testOutputAndResult() {
    String result;
    try (ConsoleOutput console = new ConsoleOutput()) {
        result = process();
        console.verifyOutput(new Options()
            .forFile()
            .withAdditionalInformation("console"));
    }
    Approvals.verify(result);
}

Creates two files: test.console.approved.txt and test.approved.txt

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