Generates standard unit tests for ShardingSphere classes to meet coverage requirements.
Install
mkdir -p .claude/skills/gen-ut && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2956" && unzip -o skill.zip -d .claude/skills/gen-ut && rm skill.zipInstalls to .claude/skills/gen-ut
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Generate standard unit tests for one or more target classes in Apache ShardingSphere; use unified rules to make target classes reach 100% class/line/branch coverage and pass quality gates.Key capabilities
- →Performs merge analysis for unit tests
- →Generates tests to achieve 100% coverage
- →Optimizes parameterized test execution
- →Maps target classes to corresponding test files
- →Integrates with quality gate enforcement
How it works
Scans production code for logic branches and generates test cases utilizing established test templates to satisfy quality metrics.
Inputs & outputs
When to use gen-ut
- →Improve unit test coverage for specific modules
- →Generate missing tests for new production classes
- →Maintain code quality gates during refactoring
About this skill
Generate Unit Tests
Input Conventions
Required inputs:
- Target class list (fully-qualified class names are recommended).
Optional inputs:
- Module name (limits Maven command scope).
- Test class list (for targeted execution only; does not limit in-place updates for related test classes).
Default completion level:
- Unless the user explicitly waives or lowers the target, requests such as "add tests" remain bound to
R10-Acompletion criteria (including default coverage and quality gates).
Missing input handling:
- Note: this section only describes entry handling; final decisions follow
R7/R10. - Missing target classes: enter
R10-INPUT_BLOCKED. - Missing test classes: auto-discover with the
TargetClassName + Testconvention. - No related test classes: create
<TargetClassName>Testin the resolved module test source set. - Cannot resolve
<ResolvedTestModules>: enterR10-INPUT_BLOCKEDand request additional module scope.
Terms
<ResolvedTestClass>: one fully-qualified test class or a comma-separated list of test classes.<ResolvedTestFileSet>: editable file set (space-separated in shell commands), containing only related test files and required test resources.<ResolvedTestModules>: comma-separated Maven module list used by scoped verification commands.<ResolvedTargetClasses>: one fully-qualified production class or a comma-separated list of target classes from user input.Target-class coverage scope: for each target class, aggregate coverage for the target binary class and all binary classes whose names start with<targetBinaryName>$(including member/anonymous/local classes).Related test classes: existingTargetClassName + Testclasses resolvable within the same module's test scope.Assertion differences: distinguishable assertions in externally observable results or side effects.Necessity reason tag: fixed-format tag for retention reasons, usingKEEP:<id>:<reason>, recorded in the "Implementation and Optimization" section of the delivery report.Baseline quality summary: one pre-edit diagnostic run that combines rule scanning, candidate summary, and coverage evidence for the current scope.Verification snapshot digest: content hash over<ResolvedTestFileSet>used to decide whether a previous green verification result is still reusable.Gate reuse state: persisted mapping from logical gate names (for exampletarget-test,coverage,rule-scan) to the latest green digest for that gate.Latest green target-test digest: compatibility alias for thetarget-testentry inGate reuse state.Consolidated hard-gate scan: one script execution that enforcesR8,R14, and all file-content-basedR15rules while still reporting results per rule.SUT-owned behavior: branches, state changes, call choices, returned values, or exception handling that the target class itself decides.Collaborator-owned behavior: rules a dependency computes, classifies, parses, loads, matches, or defaults, such as SPI, registry, factory, parser, loader, metadata option, driver option, dialect default, exception classification, message parsing, or SQLState parsing.Testing through layers: a unit test for the target class whose inputs, branch triggers, or assertions encode collaborator-owned behavior instead of mocking the collaborator result consumed by the target class.
Module resolution order:
- If the user explicitly provides modules, use them first.
- Otherwise, resolve by searching upward for the nearest parent
pom.xmlfrom<ResolvedTestFileSet>paths. - Otherwise, resolve by searching upward for the nearest parent
pom.xmlfrom target class source paths.
Mandatory Constraints
-
Norm levels:
MUST(required),SHOULD(preferred),MAY(optional). -
Definition source principle: mandatory constraints are defined only in this
R1-R15section; other sections only provide term/workflow/command descriptions and must not add, override, or relaxR1-R15. -
R1:MUSTcomply withAGENTS.mdandCODE_OF_CONDUCT.md; rule interpretation should prioritize corresponding clauses and line-number evidence inCODE_OF_CONDUCT.md. -
R2: test types and naming- Non-parameterized scenarios
MUSTuse JUnit@Test. - Data-driven scenarios
MUSTuse JUnit@ParameterizedTest(name = "{0}")with@MethodSource+Arguments. - Parameterized test method signatures
MUSTusefinal String nameas the first parameter. - Parameterized tests
MUST NOTuseConsumer(includingjava.util.function.Consumerand its generic forms) in method signatures or scenario-transport arguments. - Each parameterized test
MUSTprovide at least 3Argumentsrows; fewer than 3 is a violation andMUSTbe converted to non-parameterized@Test. - Parameterized tests
MUST NOTintroduce new nested type declarations (member/local helperclass/interface/enum/record) for scenario transport; useArgumentsrows plus existing or JDK types instead. MUST NOTuse@RepeatedTest.- Test method naming
MUSTfollowCODE_OF_CONDUCT.md: use theassertprefix; when a single test uniquely covers a production method, useassert<MethodName>.
- Non-parameterized scenarios
-
R3: change and execution scope- Edit scope
MUSTbe limited to<ResolvedTestFileSet>. - Path scope
MUSTbe limited tosrc/test/javaandsrc/test/resources. MUST NOTmodify production code or generated directories (such astarget/).MUST NOTmodify other test files to fix failures outside scope; if scope expansion is needed,MUSTbe explicitly approved by the user in the current turn.MUST NOTuse destructive git operations (for example,git reset --hard,git checkout --).
- Edit scope
-
R4: branch list and mapping- Before coding,
MUSTenumerate branches/paths of target public methods and build branch-to-test mappings. - Branch mapping
MUSTclassify each planned branch trigger and assertion asSUT-owned behaviororCollaborator-owned behavior. - Branch mapping
MUST NOTcount collaborator-owned rules as target-class branches; when the target class only consumes a collaborator result, map the target branch from the consumed result, not from a real collaborator implementation that happens to produce it. - Branch mapping scope
MUSTexclude Lombok-generated methods without custom logic. - By default, one branch/path maps to one test method.
- Whether to keep additional tests on the same branch is determined by
R13.
- Before coding,
-
R5: test granularity- Each test method
MUSTcover only one scenario. - Each test method
MUSTcall the target public method at most once; additional assertions are allowed in the same scenario. - For parameterized tests, each
ArgumentsrowMUSTrepresent one independent scenario and one branch/path mapping unit forR4. - For parameterized tests,
Argumentsrow countMUSTbe greater than or equal to 3. - Tests
MUSTexercise behavior through public methods only. - Coverage-relevant invocations of target public methods
MUSTappear in test method bodies together with assertions for the externally observable result of that invocation. - Helper methods and
@MethodSourceprovidersMUST NOTinvoke target public methods merely to warm caches, precompute coverage, or otherwise execute target behavior without assertions in the same test method body. - Public production methods with business logic
MUSTbe covered with dedicated test methods. - For interface targets, only
defaultpublic methods are required test targets by default, and non-defaultpublic methodsMUST NOTbe tested unless the user explicitly requests them in the current turn. - Dedicated test targets
MUSTfollow theR4branch-mapping exclusion scope.
- Each test method
-
R6: SPI, Mock, and reflection- For interface
defaultmethods, this rule overrides SPI instantiation requirements inR6: testsMUSTuse MockitoCALLS_REAL_METHODSto invoke real default implementations, and this path does not require SPI-bypass justification. - If the class under test can be obtained via SPI,
MUSTinstantiate by default withTypedSPILoader/OrderedSPILoader(or database-specific loaders), andMUSTkeep the resolved instance as a test-class-level field (global variable) by default. - SPI metadata accessor methods
TypedSPI#getType,OrderedSPI#getOrder, andgetTypeClassare default no-test-required targets. - For these accessors, tests
MUST NOTbe added by default; they are allowed only when the user explicitly requests tests for them in the current turn. - If such tests are added without explicit request, they
MUSTbe removed before completion. - If not instantiated via SPI,
MUSTrecord the reason before implementation. - Test dependencies
SHOULDuse Mockito mocks by default. - When a target-class branch depends on collaborator-owned behavior, tests
MUSTmock the nearest stable collaborator boundary to return the needed result andMUST NOTchoose a real collaborator implementation only to trigger the branch. - Simple value objects, pure data fixtures, and explicitly scoped integration, contract, or E2E tests are exceptions to the collaborator-boundary mocking rule.
- Reflection access
MUSTusePlugins.getMemberAccessor(), and field access only.
- For interface
-
R7: related test class strategy- If related test classes already exist,
MUSTupdate in place and fill missing coverage first. - If no related test class exists,
MUSTcreate<TargetClassName>Test. - If the user explicitly provides a test class list, it is only used as execution filtering input and
MUST NOTreplace the "in-place update of related test classes" strategy. - Deletion/merge of coverage-equivalent tests is determined by
R13.
- If related test classes already exist,
-
R8: parameterized optimization (enabled by default)MUSTrun pre-implementation candidate analysis and output anR8-CANDIDATESrecord (target public method, candidate co
Content truncated.
When not to use it
- →High-level integration testing
- →Writing non-Java tests
Prerequisites
Limitations
- →May generate boilerplate-heavy tests
- →Depends on existing test infrastructure
How it compares
It focuses on achieving specific statistical coverage targets (100%) rather than general verification.
Compared to similar skills
gen-ut side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| gen-ut (this skill) | 1 | 5mo | Review | Intermediate |
| springboot-tdd | 5 | 5mo | No flags | Intermediate |
| interview-solver | 0 | 3mo | No flags | Advanced |
| minecraft-bukkit-pro | 90 | 3mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by apache
View all by apache →You might also like
springboot-tdd
affaan-m
Test-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.
interview-solver
Sergiocr16
Solve a coding interview exercise (Coderbyte / LeetCode style) end-to-end. Triggers when the user pastes an interview problem, references one in `examples/`, or asks to "solve" or "resolve" an exercise — especially when they specify a target language like JavaScript, TypeScript, or Java. Runs the sa
minecraft-bukkit-pro
sickn33
Master Minecraft server plugin development with Bukkit, Spigot, and Paper APIs. Specializes in event-driven architecture, command systems, world manipulation, player management, and performance optimization. Use PROACTIVELY for plugin architecture, gameplay mechanics, server-side features, or cross-version compatibility.
java-coding-standards
affaan-m
Java coding standards for Spring Boot services: naming, immutability, Optional usage, streams, exceptions, generics, and project layout.
unit-testing
TencentBlueKing
单元测试编写指南,涵盖 JUnit5/MockK 使用、测试命名规范、Mock 技巧、测试覆盖率要求、TDD 实践。当用户编写单元测试、Mock 依赖、提高测试覆盖率或进行测试驱动开发时使用。
springboot-verification
affaan-m
Verification loop for Spring Boot projects: build, static analysis, tests with coverage, security scans, and diff review before release or PR.