skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
vekzz-dev/opencode-skills60 installs

java-springboot-testing

Expert Spring Boot testing specialist that selects the best testing techniques for your situation with JUnit and AssertJ. Trigger: When writing Spring Boot tests, need testing patterns, or working with test slices.

How do I install this agent skill?

npx skills add https://github.com/vekzz-dev/opencode-skills --skill java-springboot-testing
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    The skill is a comprehensive and secure technical guide for Spring Boot testing. It provides best practices, templates, and command examples for industry-standard tools without any malicious intent or risky behavior.

  • Socketpass

    No alerts

  • Snykpass

    Risk: LOW · No issues

What does this agent skill do?

When to Use

  • Writing tests for Spring Boot applications
  • Need help choosing the right test slice
  • Setting up test infrastructure
  • Working with MockMvc, TestRestTemplate, or RestTestClient
  • Writing integration tests with Testcontainers

Instructions

Quick Decision Tree

Testing a controller endpoint?
  Yes → @WebMvcTest with MockMvcTester

Testing repository queries?
  Yes → @DataJpaTest with Testcontainers (real DB)

Testing business logic in service?
  Yes → Plain JUnit + Mockito (no Spring context)

Testing external API client?
  Yes → @RestClientTest with MockRestServiceServer

Testing JSON mapping?
  Yes → @JsonTest

Need full integration test?
  Yes → @SpringBootTest with minimal context config

Core Principles

  1. Test Pyramid: Unit (fast) > Slice (focused) > Integration (complete)
  2. Right Tool: Use the narrowest slice that gives you confidence
  3. AssertJ Style: Fluent, readable assertions over verbose matchers
  4. Modern APIs: Prefer MockMvcTester and RestTestClient over legacy alternatives

Which Test Slice?

ScenarioAnnotationReference
Controller + HTTP semantics@WebMvcTestreferences/webmvctest.md
Endpoint security, pagination contracts, engine matrixTier 1/Tier 2 patternsreferences/endpoint-testing.md
Repository + JPA queries@DataJpaTestreferences/datajpatest.md
Repository tests on other engines / SQLiteengine varietyreferences/database-testing.md
Database state between tests, Flyway migration testingpersistence integrityreferences/database-testing.md
REST client + external APIs@RestClientTestreferences/restclienttest.md
JSON (de)serialization@JsonTestreferences/test-slices-overview.md
Full application@SpringBootTestreferences/test-slices-overview.md

Test Slices Reference

Testing Tools Reference

Assertion Libraries

Testcontainers

Test Data Generation

Database State & Migrations

Performance & Migration

Endpoint Patterns

Commands

# Run all tests
mvn test

# Run specific test class
mvn test -Dtest=OrderControllerTest

# Run tests with specific tag
mvn test -Dgroups=fast

# Run tests with Gradle
gradle test

# Run specific test with Gradle
gradle test --tests OrderControllerTest

# Run integration tests
mvn verify -P integration-test

Spring Boot 4 Highlights

  • RestTestClient: Modern alternative to TestRestTemplate
  • @MockitoBean: Replaces @MockBean (deprecated)
  • MockMvcTester: AssertJ-style assertions for web tests
  • Modular starters: Technology-specific test starters
  • Context pausing: Automatic pausing of cached contexts (Spring Framework 7)

Testing Best Practices

Code Complexity Assessment

When a method or class is too complex to test effectively:

  1. Analyze complexity - If you need more than 5-7 test cases to cover a single method, it's likely too complex
  2. Recommend refactoring - Suggest breaking the code into smaller, focused functions
  3. User decision - If the user agrees to refactor, help identify extraction points
  4. Proceed if needed - If the user decides to continue with the complex code, implement tests despite the difficulty

Example of refactoring recommendation:

// Before: Complex method hard to test
public Order processOrder(OrderRequest request) {
  // Validation, discount calculation, payment, inventory, notification...
  // 50+ lines of mixed concerns
}

// After: Refactored into testable units
public Order processOrder(OrderRequest request) {
  validateOrder(request);
  var order = createOrder(request);
  applyDiscount(order);
  processPayment(order);
  updateInventory(order);
  sendNotification(order);
  return order;
}

Avoid Code Redundancy

Create helper methods for commonly used objects and mock setup to enhance readability and maintainability.

Test Organization with @DisplayName

Use descriptive display names to clarify test intent:

@Test
@DisplayName("Should calculate discount for VIP customer")
void shouldCalculateDiscountForVip() { }

@Test
@DisplayName("Should reject order when customer has insufficient credit")
void shouldRejectOrderForInsufficientCredit() { }

Test Coverage Order

Always structure tests in this order:

  1. Main scenario - The happy path, most common use case
  2. Other paths - Alternative valid scenarios, edge cases
  3. Exceptions/Errors - Invalid inputs, error conditions, failure modes

Test Production Scenarios

Write tests with real production scenarios in mind. This makes tests more relatable and helps understand code behavior in actual production cases.

Test Coverage Goals

Aim for 80% code coverage as a practical balance between quality and effort. Higher coverage is beneficial but not the only goal.

Use Jacoco maven plugin for coverage reporting and tracking.

Coverage Rules:

  • 80+% coverage minimum
  • Focus on meaningful assertions, not just execution

What to Prioritize:

  1. Business-critical paths (payment processing, order validation)
  2. Complex algorithms (pricing, discount calculations)
  3. Error handling (exceptions, edge cases)
  4. Integration points (external APIs, databases)

Dependencies (Spring Boot 4)

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

<!-- For WebMvc tests -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webmvc-test</artifactId>
  <scope>test</scope>
</dependency>

<!-- For Testcontainers -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-testcontainers</artifactId>
  <scope>test</scope>
</dependency>

Resources

Context7 Integration

For up-to-date information on testing with Spring Boot:

  1. Resolve the libraryId - Use context7_resolve-library-id:

    • libraryName: "junit 5", "assertj", "mockito", or "spring boot test"
    • query: what you need (e.g., "mocking beans", "assertions best practices")
  2. Query the docs - Use context7_query-docs:

    • libraryId: "/junit/junit5", "/assertj/assertj", or "/spring/spring-boot"
    • query: your specific question about testing

Before writing tests, consult Context7 to get updated examples of the library you're going to use.

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/vekzz-dev/opencode-skills/java-springboot-testing">View java-springboot-testing on skillZs</a>