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.

referencesjavasetup.md

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

Java ApprovalTests Setup

Contents

For full reporter list, see reporters.md. For Options methods, see api.md.

Maven

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

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

Gradle

testImplementation 'com.approvaltests:approvaltests:VERSION'

JUnit 5 Setup

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

class MyTest {
    @Test
    void testOutput() {
        String result = generateOutput();
        Approvals.verify(result);
    }
}

With Reporter Annotation

@UseReporter(IntelliJReporter.class)
class MyTest {
    @Test
    void testOutput() {
        Approvals.verify(result);
    }
}

JUnit 4 Setup

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

public class MyTest {
    @Test
    public void testOutput() {
        String result = generateOutput();
        Approvals.verify(result);
    }
}

Dynamic Tests (JUnit 5)

import org.approvaltests.integrations.junit5.JupiterApprovals;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import java.util.stream.Stream;

class DynamicTestExample {
    @TestFactory
    Stream<DynamicTest> dynamicTests() {
        return Stream.of("hello", "world")
            .map(input -> JupiterApprovals.dynamicTest(
                "test_" + input,
                options -> Approvals.verify(process(input), options)
            ));
    }
}

Git Configuration

Add to .gitignore:

*.received.*

Add to .gitattributes:

*.approved.* binary

The binary attribute prevents line ending changes.

Reporter Selection

See reporters.md for full reporter reference including custom reporters and chaining.

Quick examples:

// IDE
@UseReporter(IntelliJReporter.class)
@UseReporter(VsCodeReporter.class)

// CI
@UseReporter(QuietReporter.class)
@UseReporter(ClipboardReporter.class)

Options Configuration

@Test
void testWithOptions() {
    Options options = new Options()
        .withReporter(new Junit5Reporter())
        .forFile().withExtension(".json");

    Approvals.verify(result, options);
}

File Naming

Default: ClassName.methodName.approved.txt

Custom naming:

Options options = new Options()
    .forFile()
    .withBaseName("custom_name")
    .withAdditionalInformation("scenario1");
// Creates: custom_name.scenario1.approved.txt

Kotlin Support

import org.approvaltests.Approvals
import org.approvaltests.core.Options
import org.junit.jupiter.api.Test

class MyTest {
    @Test
    fun `test output`() {
        val result = generateOutput()
        Approvals.verify(result)
    }
}

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