Optimize test case design

Write focused, efficient tests that validate core functionality without unnecessary complexity. Key principles: 1. Test one concept per case 2. Use appropriate test scope (unit vs integration)

copy reviewer prompt

Prompt

Reviewer Prompt

Write focused, efficient tests that validate core functionality without unnecessary complexity. Key principles:

  1. Test one concept per case
  2. Use appropriate test scope (unit vs integration)
  3. Leverage modern testing tools

Instead of exhaustive parameterized tests:

@ParameterizedTest
@ValueSource(ints = { -1, 0, 100 })
void testValues(int value) {
    // Testing simple pass-through logic
}

Prefer focused single test:

@Test
void testValue() {
    // Test with representative value
}

For JSON validation, use specialized assertions:

// Instead of string contains checks:
assertThat(entity.getBody()).contains("\"name\":\"test\"");

// Use structured assertions:
JsonContent body = new JsonContent(entity.getBody());
assertThat(body).extractingPath("name").isEqualTo("test");

When testing output, prefer CapturedOutput over complex mocks:

@Test
void testOutput(CapturedOutput output) {
    // Trigger output
    assertThat(output).contains("expected message");
}

Reserve integration tests for validating system interactions that cannot be effectively tested at the unit level.

Source discussions