スキル一覧に戻る
mduongvandinh

spring-tdd-mockito

by mduongvandinh

Java Spring Skills

3🍴 0📅 2026年1月18日
GitHubで見るManusで実行

SKILL.md


name: spring-tdd-mockito version: 1.0.0 description: | TDD (Test-Driven Development) skill with Mockito for Spring Boot. Guides the Red-Green-Refactor cycle for writing tests first.

triggers:

  • "write test"
  • "tdd"
  • "mockito"
  • "unit test"
  • "test first"

Spring Boot TDD with Mockito

TDD Cycle: Red → Green → Refactor

┌─────────────────────────────────────────────────────────────┐
│                     TDD WORKFLOW                             │
│                                                              │
│   ┌───────┐      ┌───────┐      ┌──────────┐               │
│   │  RED  │ ───→ │ GREEN │ ───→ │ REFACTOR │ ───┐          │
│   │       │      │       │      │          │    │          │
│   │ Write │      │ Write │      │ Improve  │    │          │
│   │ Test  │      │ Code  │      │ Code     │    │          │
│   └───────┘      └───────┘      └──────────┘    │          │
│       ↑                                          │          │
│       └──────────────────────────────────────────┘          │
└─────────────────────────────────────────────────────────────┘

Mockito Annotations

AnnotationPurpose
@MockCreate mock object
@InjectMocksInject mocks into class under test
@SpyPartial mock - real methods + mock behavior
@CaptorCapture arguments passed to mock
@MockBeanMock bean in Spring context

Test Template

@ExtendWith(MockitoExtension.class)
class ServiceTest {

    @Mock
    private Repository repository;

    @InjectMocks
    private Service service;

    @Test
    @DisplayName("Should do something when condition is met")
    void shouldDoSomethingWhenConditionIsMet() {
        // Given (Arrange)
        when(repository.findById(1L)).thenReturn(Optional.of(entity));

        // When (Act)
        var result = service.doSomething(1L);

        // Then (Assert)
        assertThat(result).isNotNull();
        verify(repository).findById(1L);
    }
}

Best Practices

  1. One assertion per test - Focus on single behavior
  2. Descriptive test names - Use @DisplayName
  3. AAA Pattern - Arrange, Act, Assert
  4. Test behavior, not implementation
  5. Fast tests - Mock external dependencies
  6. Isolated tests - No shared state

スコア

総合スコア

55/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

レビュー

💬

レビュー機能は近日公開予定です