Skill flagged — suspicious patterns detected

ClawHub Security flagged this skill as suspicious. Review the scan results before using.

springboot-unit-testing

专业的Spring Boot + MyBatis + MySQL项目单元测试技能,提供全面的测试覆盖策略。 当用户需要为Spring Boot项目编写单元测试时使用此技能,特别是包含: - 完整的正常流程测试 - 充分的异常场景测试 - 全面的边界值测试 - MyBatis Mapper层测试 - Service...

MIT-0 · Free to use, modify, and redistribute. No attribution required.
0 · 96 · 0 current installs · 0 all-time installs
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Suspicious
high confidence
Purpose & Capability
Name/description, templates, and example test files align with a Spring Boot + MyBatis unit-testing skill. However, some runtime requirements implied by the scripts (xmlstarlet, bc, PyYAML) are not declared in the skill metadata (clawhub.yml/package.json lists only java, maven, python). Repository URLs in metadata are placeholders (https://github.com/your-repo/...), which is inconsistent with a published package.
!
Instruction Scope
SKILL.md and included scripts instruct the agent/user to run mvn and Python scripts and to generate SQL test-data. The generated SQL includes destructive statements (DELETE FROM user; DELETE FROM order; etc.). If these SQL files are executed against a non-test/production database they could delete data. The scripts scan and read project files (src/test/java, target/site/jacoco), which is appropriate for a testing tool, but the instructions assume the user will run them in a safe test environment — that risk is not emphasized in the docs.
Install Mechanism
There is no platform install spec (instruction-only), reducing install risk. clawhub.yml includes an installation example that clones a GitHub repo, but the URL is a placeholder; the README also suggests downloading a release URL that points to a placeholder. No remote arbitrary binary downloads are present in the package itself. Overall installation behaviour is normal but repository placeholders are inconsistent and could lead a user to clone the wrong source if not corrected.
!
Credentials
The skill declares no required environment variables or credentials (good). However, the scripts rely on additional system tooling not listed anywhere: xmlstarlet (used in check-coverage.sh), bc (used in shell math), and the Python YAML library (PyYAML) used by generate-test-data.py — these are implicit dependencies. Not declaring these tools/libraries is an incoherence and will cause failures or force users to install extra tooling without guidance.
Persistence & Privilege
always:false and no requested persistence or wide privileges. The skill does create and write files under the supplied project path (test data, reports), which is expected for this purpose. It does not request system-wide configuration changes or credentials for other skills.
What to consider before installing
This skill appears to do what it claims (testing templates, coverage checks, test-data/report generation) but has several practical and safety issues you should address before using it: 1) Dangerous SQL: The generated test-data SQL contains DELETE statements (e.g., DELETE FROM user; DELETE FROM order;) — only run generated SQL against isolated test databases. Never apply these scripts to production data. 2) Undeclared tooling dependencies: The scripts expect xmlstarlet and bc (used by check-coverage.sh) and the Python YAML module (PyYAML) used by generate-test-data.py. Install these beforehand or the scripts will fail. - On Debian/Ubuntu: apt install xmlstarlet bc - Install PyYAML: pip install pyyaml 3) Placeholder repository URLs: metadata and README reference GitHub URLs like https://github.com/your-repo/… which are not real. Verify the source/maintainer before cloning from or trusting an external repo. 4) Review scripts before running: open scripts/check-coverage.sh, generate-test-data.py and generate-test-report.py and confirm they will run in your environment and won't touch production resources. Pay attention to file paths they write (they create files under the provided project root). 5) CI usage: If you integrate these scripts into CI, run them against test containers or isolated environments (e.g., Testcontainers, H2) and ensure DB credentials used by CI point to ephemeral test instances. 6) Missing dependency declarations: Consider adding a clear prerequisites section (xmlstarlet, bc, python libs) to SKILL.md or package metadata so users know what to install. If you need, I can list the exact lines in the scripts that perform destructive SQL or show a checklist you can run to safely evaluate this skill in a sandbox first.

Like a lobster shell, security has layers — review code before you run it.

Current versionv1.0.0
Download zip
latestvk97dqcqywhdx3xatmqh8yfez69839ejt

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

SKILL.md

Spring Boot + MyBatis 单元测试专家

技能概述

本技能提供Spring Boot + MyBatis + MySQL项目的专业单元测试解决方案,确保:

  1. 正常流程全面覆盖 - 所有业务逻辑都有对应的成功测试
  2. 异常场景充分测试 - 各种错误情况和异常处理都有测试验证
  3. 边界值完整验证 - 数据边界、参数边界、状态边界都有测试
  4. 分层测试策略 - Mapper、Service、Controller各层都有专业测试方法

快速开始

1. Maven依赖配置

查看 references/dependencies.md 获取完整的测试依赖配置。

2. 测试结构

  • Mapper层: 使用 @MybatisTest + H2内存数据库
  • Service层: 使用 @ExtendWith(MockitoExtension.class) + Mock依赖
  • Controller层: 使用 @WebMvcTest + MockMvc
  • 集成测试: 使用 @SpringBootTest + Testcontainers

3. 测试覆盖率目标

  • Mapper层: 90%+ (覆盖所有SQL语句)
  • Service层: 95%+ (覆盖所有业务逻辑分支)
  • Controller层: 85%+ (覆盖所有API端点)
  • 异常测试: 100% (所有异常处理逻辑)
  • 边界测试: 100% (所有边界条件)

核心测试策略

正常流程测试 (Normal Flow Testing)

每个业务方法都需要以下测试:

  • 成功场景测试: 验证方法在理想条件下的行为
  • 多数据测试: 测试不同数据组合下的表现
  • 状态转换测试: 验证状态机的正确转换
  • 并发安全测试: 确保线程安全(如果适用)

异常流程测试 (Exception Flow Testing)

每个可能抛出的异常都需要:

  • 参数验证异常: 测试无效参数的异常处理
  • 业务逻辑异常: 测试业务规则违反的异常
  • 数据不存在异常: 测试查询不到数据的异常
  • 并发异常: 测试并发冲突的异常处理
  • 外部依赖异常: 测试外部服务失败的异常

边界值测试 (Boundary Value Testing)

所有输入参数都需要边界测试:

  • 数值边界: 最小/最大/临界值测试
  • 字符串边界: 空/null/最大长度/特殊字符测试
  • 集合边界: 空集合/单元素/最大容量测试
  • 时间边界: 最小/最大时间/时区边界测试
  • 状态边界: 初始/中间/最终状态测试

测试模板

Mapper层测试模板

// 查看完整模板: references/mapper-test-template.java
@MybatisTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
@Sql("/test-data.sql")
class [Entity]MapperTest {
    // CRUD操作测试
    // 复杂查询测试  
    // 事务边界测试
    // 性能边界测试
}

Service层测试模板

// 查看完整模板: references/service-test-template.java  
@ExtendWith(MockitoExtension.class)
class [Entity]ServiceTest {
    // 业务逻辑测试
    // 异常处理测试
    // 事务管理测试
    // 并发安全测试
}

Controller层测试模板

// 查看完整模板: references/controller-test-template.java
@WebMvcTest([Entity]Controller.class)
class [Entity]ControllerTest {
    // HTTP方法测试
    // 请求参数测试
    // 响应格式测试
    // 错误处理测试
}

集成测试模板

// 查看完整模板: references/integration-test-template.java
@SpringBootTest
@AutoConfigureMockMvc
@Transactional
class [Feature]IntegrationTest {
    // 端到端流程测试
    // 数据一致性测试
    // 性能基准测试
    // 安全边界测试
}

测试数据管理

测试数据策略

  1. 静态测试数据: 使用 @Sql 注解导入SQL文件
  2. 动态测试数据: 使用Builder模式创建测试对象
  3. 随机测试数据: 使用Faker库生成随机数据
  4. 边界测试数据: 专门测试边界条件的数据

测试数据工厂

查看 references/test-data-factory.java 获取测试数据工厂实现。

SQL测试数据文件

查看 references/test-data-examples.sql 获取测试SQL示例。

特殊场景测试

1. 事务测试

@Test
@Transactional(propagation = Propagation.NEVER)
void testTransactionRollback() {
    // 测试事务回滚
}

@Test  
void testTransactionPropagation() {
    // 测试事务传播
}

2. 并发测试

@Test
void testConcurrentAccess() throws InterruptedException {
    // 使用CountDownLatch或CompletableFuture测试并发
}

3. 性能测试

@Test
@Timeout(5) // 5秒超时
void testPerformanceBoundary() {
    // 性能边界测试
}

4. 安全测试

@Test
void testSecurityConstraints() {
    // 权限验证测试
    // 数据隔离测试
}

测试工具和最佳实践

断言选择指南

  • 基本断言: 使用JUnit 5的 assertEquals()assertThrows()
  • 流式断言: 使用AssertJ的 assertThat() 链式调用
  • 匹配器断言: 使用Hamcrest的 assertThat() + Matcher
  • 自定义断言: 创建领域特定的断言方法

Mock使用指南

  • 最小化Mock: 只Mock外部依赖
  • 验证调用: 使用 verify() 验证方法调用
  • 参数匹配: 使用 any(), eq(), argThat()
  • 异常模拟: 使用 when().thenThrow() 模拟异常

测试生命周期

  • @BeforeEach: 准备测试数据
  • @AfterEach: 清理测试数据
  • @BeforeAll: 初始化测试环境
  • @AfterAll: 清理测试环境

质量保证

代码覆盖率检查

# 生成覆盖率报告
mvn clean test jacoco:report

# 检查覆盖率阈值
mvn jacoco:check

测试代码质量

  • 可读性: 测试代码应该像文档一样清晰
  • 可维护性: 避免重复代码,使用工厂模式
  • 可执行性: 测试应该快速执行,独立运行
  • 可调试性: 提供清晰的失败信息

测试命名规范

  • 方法名: test[场景]_[条件]_[期望结果]
  • 测试类: [Entity][Layer]Test
  • 数据工厂: TestDataFactory
  • 测试文件: test-[feature].sql

故障排除

常见问题

  1. 事务不回滚: 检查 @Transactional 注解位置
  2. Mock不生效: 检查 @MockBean@Mock 的区别
  3. 数据库连接失败: 检查H2数据库配置
  4. 测试数据污染: 使用 @Transactional 或清理方法

调试技巧

  • 启用详细日志: logging.level.root=DEBUG
  • 使用 @DirtiesContext 重置Spring上下文
  • 使用 @TestPropertySource 覆盖配置
  • 使用 MockMvcandDo(print()) 打印请求详情

扩展和定制

自定义测试注解

// 创建组合注解简化测试配置
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@MybatisTest
@AutoConfigureTestDatabase
@Sql("/test-data.sql")
public @interface MybatisIntegrationTest {
}

测试工具扩展

  • 自定义Matcher: 创建领域特定的Matcher
  • 测试监听器: 实现TestExecutionListener
  • 自定义Runner: 扩展SpringJUnit4ClassRunner
  • 测试扩展: 实现Extension接口

性能优化

  • 测试分组: 使用 @Tag 分组测试
  • 并行执行: 配置Maven Surefire并行执行
  • 数据库优化: 使用H2内存数据库模式
  • Mock优化: 避免不必要的Mock初始化

参考资源

核心文档

最佳实践

工具脚本

使用示例

当用户请求"为我的Spring Boot项目编写单元测试"时:

  1. 分析项目结构 - 识别Entity、Mapper、Service、Controller
  2. 选择测试策略 - 根据需求选择正常/异常/边界测试
  3. 生成测试代码 - 使用模板生成对应层的测试
  4. 配置测试环境 - 设置依赖、数据、配置
  5. 验证测试覆盖 - 检查覆盖率,补充缺失测试

本技能确保为每个Spring Boot项目提供专业、全面、可维护的单元测试解决方案。


📦 发布信息

ClawHub发布配置

此Skill已配置为可发布到ClawHub的技能市场。包含以下发布文件:

  1. clawhub.yml - 发布配置文件
  2. package.json - 标准化包描述
  3. LICENSE - MIT许可证
  4. README.md - 完整使用说明

发布准备检查清单

完整性检查

  • SKILL.md - 主技能文件
  • README.md - 使用文档
  • scripts/ - 3个实用脚本
  • references/ - 4个参考文档
  • examples/ - 2个示例测试代码
  • assets/ - 资源文件夹

配置检查

  • clawhub.yml - 发布配置
  • package.json - 包管理
  • LICENSE - 许可证文件

质量检查

  • 测试策略文档齐全
  • 代码示例完整可运行
  • 工具脚本可用
  • 依赖配置正确

发布到ClawHub的步骤

  1. 创建GitHub仓库(推荐)

    git init
    git add .
    git commit -m "feat: Spring Boot单元测试Skill v1.0.0"
    git remote add origin https://github.com/your-repo/springboot-unit-testing.git
    git push -u origin main
    
  2. 准备发布包

    # 打包Skill
    tar -czf springboot-unit-testing-skill-v1.0.0.tar.gz test-skill/
    
    # 或使用zip
    zip -r springboot-unit-testing-skill-v1.0.0.zip test-skill/
    
  3. 发布到ClawHub

    • 访问ClawHub网站 (https://clawhub.com)
    • 注册/登录开发者账户
    • 创建新Skill发布
    • 填写Skill信息(参考clawhub.yml)
    • 上传打包文件
    • 设置分类标签:spring-boot, testing, java
    • 提交审核
  4. 维护和更新

    • 定期更新测试策略
    • 收集用户反馈
    • 发布新版本
    • 更新文档

Skill分类信息

  • 类别: 开发工具 / 测试框架
  • 技术栈: Spring Boot, MyBatis, MySQL, JUnit 5
  • 适用场景: 企业级Java项目单元测试
  • 难度级别: 中级(需要Java和Spring Boot基础)
  • 预估时间: 使用此Skill可减少50%的测试开发时间

用户支持

  • 文档: 完整的README和示例代码
  • 问题反馈: 通过GitHub Issues
  • 社区: 分享测试经验和最佳实践
  • 贡献: 欢迎提交PR改进Skill

版本历史

  • v1.0.0 (2026-03-20) - 初始发布
    • 完整的Spring Boot单元测试策略
    • 正常流程、异常测试、边界值测试全面覆盖
    • 3个实用工具脚本
    • 4个详细参考文档
    • 2个完整代码示例

让Spring Boot项目的单元测试更专业、更全面、更高效!

Files

15 total
Select a file
Select a file to preview.

Comments

Loading comments…