OpenParable
Skip to content
← Back to skills

Spring TDD Mockito

Testing & Quality
spring-tdd-mockito

Spring TDD Mockito is an Agent Skill for testing & quality published in the majiayu000/claude-skill-registry repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

TDD (Test-Driven Development) skill with Mockito for Spring Boot. Guides the Red-Green-Refactor cycle for writing tests first.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/majiayu000/claude-skill-registry/blob/HEAD/skills/data/spring-tdd-mockito/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/spring-tdd-mockito, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

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