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

unit-tests单元测试

Agent Skill

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

总安装

245

周安装

10

GitHub Stars

公开资料未说明

下载量

79
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/andresnator/agents-orchestrator --skill unit-tests

简介

用于辅助测试设计、自动化测试、用例整理和回归验证。

  • 适合编写单元测试、端到端测试、测试计划或根据失败日志定位问题。
  • 使用时需确认项目测试框架、运行命令和夹具数据,避免为通过测试而改坏真实逻辑。
  • 涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。
  • unit-tests 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Adding Unit Tests (Multi-Language)

Use this skill when the user requests the creation or update of unit tests in any project. Detects the language and test framework automatically to generate idiomatic tests.

Step 0: Detect Language and Test Ecosystem

Before generating any test, detect the project's stack:

LanguageTest FrameworkMocking ToolAssertion StyleTest Location
JavaJUnit 5MockitoAssertJ assertThat()src/test/java/ mirroring packages
Pythonpytestunittest.mock / pytest-mockassert (plain) or pytest assertionstests/ mirroring source, or test_*.py alongside
TypeScriptJest / Vitestjest.mock / vi.mock / jest.spyOnexpect().toBe() / expect().toEqual()__tests__/ or *.test.ts / *.spec.ts alongside
JavaScriptJest / Vitest / Mochajest.mock / sinonexpect()__tests__/ or *.test.js / *.spec.js alongside
C#xUnit / NUnitMoq / NSubstituteAssert.Equal() / FluentAssertions Should()*.Tests project mirroring namespace
Gotesting (stdlib)testify/mock / gomock / interfacesassert.Equal() (testify) or if got!= want*_test.go same package
KotlinJUnit 5 / KotestMockKKotest matchers or AssertJsrc/test/kotlin/ mirroring packages
RubyRSpec / Minitestrspec-mocks / mochaexpect().to eq() / assert_equalspec/ or test/ mirroring source
PHPPHPUnit / PestMockery / PHPUnit mocks$this->assertEquals() / assertThat()tests/ mirroring namespace
Rust#[test] (stdlib)mockall (traits)assert_eq! / assert!#[cfg(test)] mod tests in same file, or tests/
SwiftXCTest / Quick+NimbleProtocol-based mockingXCTAssertEqual() / expect().to(equal())*Tests/ target

Detection heuristic: Check project files — pom.xml/build.gradle → Java, package.json → TS/JS, pyproject.toml/requirements.txt/setup.py → Python, *.csproj → C#, go.mod → Go, Cargo.toml → Rust, Gemfile → Ruby, composer.json → PHP, Package.swift → Swift, build.gradle.kts → Kotlin.

If the language is Java and the user needs detailed JUnit 5 / Mockito / AssertJ reference examples, delegate to the unit-tests-java skill.

Instructions

Follow these steps to generate unit tests in any language:

  1. Detect the language and test framework (Step 0)
  2. Naming Convention: Use the language's idiomatic test naming (see Naming Conventions by Language)
  3. Structure: Follow the Arrange/Act/Assert (AAA) pattern — expressed idiomatically per language
  4. Minimal comments: Only use // Arrange, // Act, // Assert (or language equivalent) section markers. No other comments or docstrings unless absolutely necessary.
  5. Select Pattern: Choose the appropriate testing pattern below based on the verification need
  6. Mocking: Use the language's standard mocking tool (see Step 0 table). Prefer constructor/parameter injection over monkey-patching.

Naming Conventions by Language

LanguageTest FileTest Class/SuiteTest Method/Function
Java{ClassName}Test.java{ClassName}Testshould{Behavior}When{Condition}
Pythontest_{module}.pyTest{ClassName} (or no class with pytest)test_should_{behavior}_when_{condition}
TypeScript/JS{module}.test.ts or {module}.spec.tsdescribe('{ClassName}')it('should {behavior} when {condition}')
C#{ClassName}Tests.cs{ClassName}TestsShould{Behavior}_When{Condition}
Go{file}_test.go(none — package-level)Test{Function}_{Condition}
Kotlin{ClassName}Test.kt{ClassName}Test` should {behavior} when {condition} ` (backtick) or camelCase
Ruby{class}_spec.rb (RSpec)RSpec.describe {ClassName}it '{behavior} when {condition}'
PHP{ClassName}Test.php{ClassName}Testtest_{behavior}_when_{condition} or testShouldBehaviorWhenCondition
Rustsame file (mod tests) or tests/{name}.rsmod testsfn test_{behavior}_when_{condition}()
Swift{ClassName}Tests.swift{ClassName}Tests: XCTestCasetest_{behavior}_when_{condition}()

Patterns

Pattern 1: Basic Mock Test

Test a unit with mocked dependencies.

Java (JUnit 5 + Mockito + AssertJ):

@ExtendWith(MockitoExtension.class)
class OrderServiceTest implements WithAssertions {
    @Mock private OrderRepository repository;
    @InjectMocks private OrderService service;

    @Test
    void shouldReturnOrderWhenIdExists() {
        // Arrange
        when(repository.findById(1L)).thenReturn(Optional.of(order));
        // Act
        var result = service.getOrder(1L);
        // Assert
        assertThat(result).isEqualTo(order);
    }
}

Python (pytest + unittest.mock):

from unittest.mock import Mock

def test_should_return_order_when_id_exists():
    # Arrange
    repository = Mock()
    repository.find_by_id.return_value = order
    service = OrderService(repository)
    # Act
    result = service.get_order(1)
    # Assert
    assert result == order

TypeScript (Jest):

describe('OrderService', () => {
  it('should return order when id exists', () => {
    // Arrange
    const repository = { findById: jest.fn().mockReturnValue(order) };
    const service = new OrderService(repository);
    // Act
    const result = service.getOrder(1);
    // Assert
    expect(result).toEqual(order);
  });
});

C# (xUnit + Moq):

public class OrderServiceTests {
    [Fact]
    public void ShouldReturnOrder_WhenIdExists() {
        // Arrange
        var repository = new Mock<IOrderRepository>();
        repository.Setup(r => r.FindById(1)).Returns(order);
        var service = new OrderService(repository.Object);
        // Act
        var result = service.GetOrder(1);
        // Assert
        Assert.Equal(order, result);
    }
}

Go (testing + testify):

func TestGetOrder_WhenIdExists(t *testing.T) {
	// Arrange
	repo := new(MockOrderRepository)
	repo.On("FindById", 1).Return(order, nil)
	service := NewOrderService(repo)
	// Act
	result, err := service.GetOrder(1)
	// Assert
	assert.NoError(t, err)
	assert.Equal(t, order, result)
}

Rust (mockall):

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

    #[test]
    fn test_get_order_when_id_exists() {
        // Arrange
        let mut repo = MockOrderRepository::new();
        repo.expect_find_by_id().with(eq(1)).returning(|_| Ok(order));
        let service = OrderService::new(Box::new(repo));
        // Act
        let result = service.get_order(1).unwrap();
        // Assert
        assert_eq!(result, order);
    }
}

Pattern 2: Parameterized / Table-Driven Tests

Test multiple data variations with a single test structure.

Java (JUnit 5):

@ParameterizedTest
@MethodSource("invalidInputs")
void shouldRejectWhenInputInvalid(String input, String expectedError) {
    assertThatThrownBy(() -> service.validate(input))
        .hasMessage(expectedError);
}

static Stream<Arguments> invalidInputs() {
    return Stream.of(
        Arguments.of("", "must not be empty"),
        Arguments.of(null, "must not be null")
    );
}

Python (pytest.mark.parametrize):

@pytest.mark.parametrize("input_val, expected_error", [
    ("", "must not be empty"),
    (None, "must not be null"),
])
def test_should_reject_when_input_invalid(input_val, expected_error):
    with pytest.raises(ValueError, match=expected_error):
        service.validate(input_val)

TypeScript (Jest each):

it.each([
  ['', 'must not be empty'],
  [null, 'must not be null'],
])('should reject when input is %s', (input, expectedError) => {
  expect(() => service.validate(input)).toThrow(expectedError);
});

Go (table-driven):

func TestValidate_InvalidInputs(t *testing.T) {
	tests := []struct {
		name  string
		input string
		want  string
	}{
		{"empty", "", "must not be empty"},
		{"whitespace", "  ", "must not be blank"},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			err := service.Validate(tt.input)
			assert.EqualError(t, err, tt.want)
		})
	}
}

Rust (macro or loop):

#[test]
fn test_validate_invalid_inputs() {
    let cases = vec![
        ("", "must not be empty"),
        ("  ", "must not be blank"),
    ];
    for (input, expected) in cases {
        let err = service.validate(input).unwrap_err();
        assert_eq!(err.to_string(), expected);
    }
}

Pattern 3: Exception / Error Testing

Verify that errors are thrown/returned correctly. Each language has its own idiom:

LanguageException/Error assertion
JavaassertThatThrownBy(() -> svc.process(null)).isInstanceOf(IllegalArgumentException.class).hasMessage("input required")
Pythonwith pytest.raises(ValueError, match="input required"): svc.process(None)
TypeScriptexpect(() => svc.process(null)).toThrow('input required') — async: await expect(svc.processAsync(null)).rejects.toThrow(...)
C#Assert.Throws<ArgumentException>(() => svc.Process(null))
Go_, err:= svc.Process(""); assert.EqualError(t, err, "input required")
Rustlet err = svc.process("").unwrap_err(); assert_eq!(err.to_string(), "input required")

Pattern 4: Spy / Verify Interactions

Verify that a dependency was called with specific arguments.

LanguageVerification idiom
JavaArgumentCaptor<Event> c = ArgumentCaptor.forClass(Event.class); verify(pub).publish(c.capture()); assertThat(c.getValue().getType()).isEqualTo("ORDER_CREATED")
Pythonpub.publish.assert_called_once(); event = pub.publish.call_args[0][0]; assert event.type == "ORDER_CREATED"
TypeScriptexpect(pub.publish).toHaveBeenCalledWith(expect.objectContaining({type: 'ORDER_CREATED'}))
Gorepo.AssertCalled(t, "Save", mock.MatchedBy(func(o Order) bool {return o.Status == "CREATED"}))

Pattern 5: Async Test

Test asynchronous code — only applies to languages with async support.

TypeScript (Jest):

it('should fetch data', async () => {
  api.get.mockResolvedValue({ data: expected });
  const result = await service.fetchData();
  expect(result).toEqual(expected);
});

Python (pytest-asyncio):

@pytest.mark.asyncio
async def test_should_fetch_data():
    api.get = AsyncMock(return_value=expected)
    result = await service.fetch_data()
    assert result == expected

Rust (tokio::test):

#[tokio::test]
async fn test_fetch_data() {
    let mut api = MockApi::new();
    api.expect_get().returning(|_| Ok(expected));
    let service = Service::new(Box::new(api));
    let result = service.fetch_data().await.unwrap();
    assert_eq!(result, expected);
}

Checklist

  • Detected language and test framework correctly
  • Test file location follows project convention
  • Test naming follows language idiom (see naming table)
  • Arrange/Act/Assert structure is clear
  • Only section-marker comments — no unnecessary docs
  • Mocking uses the standard tool for the language
  • Verify calls only when interaction matters (not on every mock)
  • Assertions are idiomatic for the framework
  • Test is complete and runnable (all imports/requires included)

Reference Examples

For Java-specific compiled reference examples (JUnit 5 + Mockito + AssertJ), see the unit-tests-java skill which includes:

  • ExampleServiceTest.java - Basic Mockito tests with @Mock and @InjectMocks
  • ExampleConfigTest.java - Configuration class testing with property injection
  • ExampleHandlerTest.java - Handler testing with ArgumentCaptor
  • ExampleListenerTest.java - Event listener testing with complex mocking
  • ExampleCacheTest.java - Cache testing with parameterized tests and edge cases

For all other languages, use the multi-language patterns documented above in this skill.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

36.16%
按下载量换算29

Claude

29.31%
按下载量换算23

Cursor

21.7%
按下载量换算17

Gemini CLI

8.94%
按下载量换算7

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

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

来源信息

继续浏览同类 Skills