Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

rust-testingRust 测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

1,630

周安装

70

GitHub Stars

4

下载量

571
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:rust-testing(Rust 测试)
来源仓库:https://github.com/autumnsgrove/groveengine
仓库路径:skills/rust-testing
安装命令:
npx skills add https://github.com/autumnsgrove/groveengine --skill rust-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/autumnsgrove/groveengine --skill rust-testing

简介

rust-testing 用于辅助测试设计、自动化测试、用例整理和回归验证,适合编写 Rust 单元测试或集成测试。

  • 支持 doc tests、属性化测试和基准测试,提供 cargo test 的完整命令集和测试组织方式。
  • 可生成测试模块、mock 依赖和使用 super 引用父级函数,提升测试可维护性。
  • 安装命令为 npx skills add https://github.com/autumnsgrove/groveengine --skill rust-testing。
  • 建议确认项目 Cargo.toml 配置和测试入口,避免因路径错误导致编译失败。

SKILL.md

Rust Testing Skill

When to Activate

Activate this skill when:

  • Writing Rust unit tests
  • Creating integration tests
  • Working with doc tests
  • Setting up property-based testing
  • Running benchmarks

Quick Commands

# Run all tests
cargo test

# With output
cargo test -- --nocapture

# Run specific test
cargo test test_user_create

# Run tests in module
cargo test auth::

# Run ignored tests
cargo test -- --ignored

# Doc tests only
cargo test --doc

# Integration tests only
cargo test --test integration

Unit Tests (Same File)

pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_add() {
        assert_eq!(add(2, 3), 5);
    }

    #[test]
    fn test_add_negative() {
        assert_eq!(add(-1, -1), -2);
    }
}

Test Attributes

#[test]
fn regular_test() { }

#[test]
#[ignore]
fn slow_test() { }  // Skip unless --ignored

#[test]
#[should_panic]
fn test_panic() {
    panic!("This should panic");
}

#[test]
#[should_panic(expected = "specific message")]
fn test_panic_message() {
    panic!("specific message here");
}

#[test]
fn test_with_result() -> Result<(), String> {
    let result = some_operation()?;
    assert_eq!(result, expected);
    Ok(())
}

Assertions

// Basic
assert_eq!(1 + 1, 2);
assert_ne!(1 + 1, 3);
assert!(true);

// With messages
assert_eq!(result, expected, "values should match: got {}", result);

// Pattern matching
assert!(matches!(value, Pattern::Variant(_)));

// Option/Result
assert!(some_option.is_some());
assert!(some_result.is_ok());

Integration Tests

// tests/api_integration.rs
use my_crate::{Config, Server};

#[test]
fn test_server_startup() {
    let config = Config::default();
    let server = Server::new(config);
    assert!(server.start().is_ok());
}

Directory Structure

project/
├── Cargo.toml
├── src/
│   ├── lib.rs          # Unit tests in #[cfg(test)]
│   └── user.rs         # Module with inline tests
└── tests/              # Integration tests
    ├── common/
    │   └── mod.rs      # Shared utilities
    └── api_test.rs

Mocking with Traits

pub trait UserRepository {
    fn find_by_id(&self, id: u64) -> Option<User>;
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::HashMap;

    struct MockUserRepo {
        users: HashMap<u64, User>,
    }

    impl UserRepository for MockUserRepo {
        fn find_by_id(&self, id: u64) -> Option<User> {
            self.users.get(&id).cloned()
        }
    }

    #[test]
    fn test_user_service() {
        let mut users = HashMap::new();
        users.insert(1, User { id: 1, email: "test@example.com".into() });
        let repo = MockUserRepo { users };

        let service = UserService::new(Box::new(repo));
        let user = service.get_user(1).unwrap();
        assert_eq!(user.email, "test@example.com");
    }
}

Async Testing (tokio)

#[tokio::test]
async fn test_async_operation() {
    let result = fetch_data().await;
    assert!(result.is_ok());
}

#[tokio::test]
async fn test_with_timeout() {
    let result = tokio::time::timeout(
        Duration::from_secs(5),
        slow_operation()
    ).await;
    assert!(result.is_ok());
}

Doc Tests

/// Adds two numbers together.
///
/// # Examples
///
/// ```
/// use my_crate::add;
/// let result = add(2, 3);
/// assert_eq!(result, 5);
/// ```
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

Property-Based Testing (proptest)

use proptest::prelude::*;

proptest! {
    #[test]
    fn test_add_commutative(a: i32, b: i32) {
        prop_assert_eq!(add(a, b), add(b, a));
    }
}

Coverage

# Using cargo-tarpaulin
cargo install cargo-tarpaulin
cargo tarpaulin --out Html

# Using cargo-llvm-cov
cargo install cargo-llvm-cov
cargo llvm-cov --html

Related Resources

See AgentUsage/testing_rust.md for complete documentation including:

  • Benchmarking with criterion
  • Setup/teardown patterns
  • Mockall crate usage
  • CI configuration

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.79%
按下载量换算204

Claude

30.14%
按下载量换算172

Cursor

19.56%
按下载量换算112

Gemini CLI

9.41%
按下载量换算54

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills