CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/springboot-testing

Spring Boot testing — @WebMvcTest for controllers, @DataJpaTest for repositories, @SpringBootTest only for integration, MockMvc, @MockBean vs @Mock, AssertJ, @Transactional rollback, @ActiveProfiles, TestContainers

93

1.09x
Quality

89%

Does it follow best practices?

Impact

100%

1.09x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

springboot-repository-tests.jsonverifiers/

{
  "instruction": "Write tests for a Spring Boot product catalog repository. The Product entity has fields: id, name, category, price, inStock. The ProductRepository extends JpaRepository and has custom methods: findByCategory(String category), findByPriceLessThan(BigDecimal maxPrice), findByInStockTrue().",
  "relevant_when": "Agent writes tests for a Spring Boot JPA repository",
  "context": "Proactively check that agents use @DataJpaTest for repository tests (not @SpringBootTest), leverage auto-rollback via @Transactional, use TestEntityManager for test data setup, and use AssertJ for assertions.",
  "sources": [
    {
      "type": "file",
      "filename": "skills/springboot-testing/SKILL.md",
      "tile": "tessl-labs/springboot-testing"
    }
  ],
  "checklist": [
    {
      "name": "datajpatest-annotation",
      "rule": "Agent uses @DataJpaTest on the test class, NOT @SpringBootTest. @DataJpaTest loads only JPA components and auto-configures an embedded database.",
      "relevant_when": "Agent creates a test class for a Spring Boot JPA repository"
    },
    {
      "name": "repository-autowired",
      "rule": "Agent autowires the repository under test with @Autowired",
      "relevant_when": "Agent writes repository tests"
    },
    {
      "name": "test-entity-manager-or-repository-setup",
      "rule": "Agent uses TestEntityManager (persistAndFlush) or the repository itself to set up test data before running assertions",
      "relevant_when": "Agent creates test data for repository tests"
    },
    {
      "name": "assertj-assertions",
      "rule": "Agent uses AssertJ assertThat() for assertions instead of JUnit assertEquals/assertTrue. Examples: assertThat(results).hasSize(2), assertThat(results).extracting(Product::getName).contains(\"Widget\")",
      "relevant_when": "Agent writes assertions in Spring Boot tests"
    },
    {
      "name": "no-manual-cleanup",
      "rule": "Agent does NOT manually call deleteAll() or truncate in @BeforeEach/@AfterEach. @DataJpaTest is @Transactional by default and auto-rolls back after each test.",
      "relevant_when": "Agent sets up test isolation for repository tests"
    },
    {
      "name": "custom-query-tested",
      "rule": "Agent tests at least one custom query method (findByCategory, findByPriceLessThan, or findByInStockTrue) to verify the query derivation works correctly",
      "relevant_when": "Agent writes tests for a repository with custom finder methods"
    },
    {
      "name": "empty-result-test",
      "rule": "Agent includes a test that verifies a query returns an empty result when no entities match the criteria",
      "relevant_when": "Agent writes repository query tests"
    }
  ]
}

tile.json