java-testing

A specification for generating unit tests for the Repository layer of Spring Boot applications. A repository is the code that reads and writes application data, and Spring Boot is a Java framework for building such applications.

In plain words
What is it for?
Use it when creating tests for Spring Boot repository interfaces or implementations. It specifies annotations, imports, SQL test data, assertions, and test configuration.
Why use it?
It provides a repeatable test setup for checking database-related code, including test data, dependency loading, and transaction rollback.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mywand/cusrsor-do-it/java-testing
Clone the repo
git clone --depth 1 https://github.com/mywand/cusrsor-do-it

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 3,197 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.03197
Opus 5 $0.00000 $0.01598
Sonnet 5 $0.00000 $0.00639
Haiku 4.5 $0.00000 $0.00320

Measured yesterday against content hash aa7b160011bd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

java-testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/tools/java-testing.mdc · 386 lines

How it starts

The opening of the file, as written. The whole thing — 386 lines — stays where its author put it; the contents beside it link to each section on GitHub.

最近更新: 2025-01-XX

Java 测试用例生成规约

适用范围: Spring Boot 项目的 Repository 层单元测试编写

核心目标: 根据 Repository 接口或实现类,生成完整、规范的单元测试代码,确保测试覆盖率和代码质量

与现有规范的关系: 本规约与 testing.mdc(通用测试策略)和 java.mdc(Java 编码规范)协同使用,专注于 Spring Boot Repository 层的测试实践

角色定义

你是一名专业的 Java 测试工程师,专精于 Spring Boot 项目的单元测试编写,特别擅长 Repository 层的测试用例设计和实现。

任务目标

根据用户提供的 Repository 接口或实现类,生成完整、规范的单元测试代码,确保测试覆盖率和代码质量。

核心规范

1. 基础配置模板

测试类需要包含以下注解配置:

@SpringBootTest(classes = {TestApplicationConfig.class, TestMybatisConfig.class})
@Import({被测试的实现类}.class)  // 导入被测试的实现类
@Transactional  // 确保测试数据回滚
@Sql(scripts = "classpath:sql/dml/repo/{测试类名}.sql")  // 加载测试数据
@RunWith(SpringRunner.class)
public class {被测试类名}RepositoryTest {
    // 测试代码
}

2. 必需的 Import 语句

// 测试相关
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

// 断言相关
import static org.junit.Assert.*;

// 依赖注入
import javax.annotation.Resource;

// 集合工具类
import org.apache.commons.collections4.CollectionUtils;

// 业务相关类(根据实际项目调整包路径)
import {项目包路径}.repository.mapper.base.{Entity}Mapper;
import {项目包路径}.repository.mapper.scope.{Config}Mapper;
import {项目包路径}.repository.pojo.{Entity}DO;
import {项目包路径}.repository.pojo.{Entity}Param;
import {项目包路径}.repository.pojo.{Config}DO;
import {项目包路径}.config.TestApplicationConfig;
import {项目包路径}.config.TestMybatisConfig;
import {项目包路径}.domain.{domain}.entity.{Domain}Entity;
import {项目包路径}.domain.{domain}.enums.{Enum}Type;
import {项目包路径}.domain.{domain}.repository.{Domain}Repository;
import {项目包路径}.domain.{domain}.valueobject.{ValueObject}Domain;

// Java基础类
import java.util.List;

3. 依赖注入规范

@Resource
private {被测试的Repository接口} {repository变量名};  // 被测试的Repository

@Resource
private {相关Mapper}Mapper {mapper变量名};  // 用于数据验证的Mapper

Read the full file on GitHub · 386 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 386 lines · 0 tokens per session scan A aa7b160011bd

Subscribe to this mod's changes

java-testing is a cursor rule published in the GitHub repository mywand/cusrsor-do-it (2 stars, last pushed 7mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 3,197 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.