agentleFS
KaratussKaratuss/bstack/skills/test/SKILL.md

test

Skill0 starsChanged 7 months agoMITView on GitHub

TestContainers·Mockito·슬라이스 테스트·커버리지 전략. Mock vs 실제 의존성 결정 시 사용.

179 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use agent-context-isolation, agentica-infrastructure and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.

The file

Files
SKILL.md

/test — 테스트 전략 스킬

TestContainers, Mockito, 슬라이스 테스트, 커버리지 전략을 다룬다.

When to use

  • 테스트 전략 수립 (단위 vs 통합)
  • TestContainers 설정
  • Mockito vs 실제 의존성 판단
  • 커버리지 80%+ 달성 전략
  • 슬라이스 테스트 (@WebMvcTest, @DataJpaTest)

핵심 원칙: 무엇을 Mock하고 무엇을 실제로 쓸까

의존성권장 방식이유
데이터베이스TestContainers (실제)Mock/실제 불일치로 프로덕션 버그 발생
외부 HTTP APIWireMock (Mock)외부 서비스 불안정성 격리
이메일/SMSMock실제 발송 방지
파일 시스템임시 디렉터리테스트 격리
메시지 브로커TestContainers (실제)메시지 순서/트랜잭션 검증 필요

TestContainers 설정

@SpringBootTest
@Testcontainers
class OrderServiceIntegrationTest {

    @Container
    static MySQLContainer<?> mysql = new MySQLContainer<>("mysql:8.4")
        .withDatabaseName("testdb")
        .withUsername("test")
        .withPassword("test");

    @DynamicPropertySource
    static void configureProperties(DynamicPropertyRegistry registry) {
        registry.add("spring.datasource.url", mysql::getJdbcUrl);
        registry.add("spring.datasource.username", mysql::getUsername);
        registry.add("spring.datasource.password", mysql::getPassword);
    }

    @Test
    void 주문_생성_성공() {
        // given / when / then
    }
}

슬라이스 테스트

// Controller 레이어만 (빠름)
@WebMvcTest(OrderController.class)
class OrderControllerTest {
    @Autowired MockMvc mockMvc;
    @MockBean OrderService orderService;  // Service는 Mock

    @Test
    void 주문_조회_200() throws Exception {
        given(orderService.getOrder(1L)).willReturn(sampleOrder());
        mockMvc.perform(get("/api/v1/orders/1"))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.id").value(1));
    }
}

// Repository 레이어만
@DataJpaTest
@AutoConfigureTestDatabase(replace = NONE)  // TestContainers 사용 시
class OrderRepositoryTest {
    @Autowired OrderRepository repository;
}

Context Rot 방지 (테스트 출력)

// application-test.yml
logging:
  level:
    org.hibernate.SQL: OFF      # 성공 시 SQL 로그 끄기
    org.testcontainers: WARN    # 컨테이너 시작 로그 최소화

테스트 실행 후:

  • 성공: Tests: 42 passed (한 줄)
  • 실패: 실패 케이스 스택트레이스 전체 출력

커버리지 전략

<!-- pom.xml JaCoCo 설정 -->
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/*Request.class</exclude>
            <exclude>**/*Response.class</exclude>
            <exclude>**/config/**</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals><goal>check</goal></goals>
            <configuration>
                <rules>
                    <rule>
                        <limits>
                            <limit>
                                <counter>LINE</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.80</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

테스트 명명 규칙

// 한국어 설명 또는 영어 given_when_then
@Test
void 재고_부족_시_주문_생성_실패() { ... }

@Test
void createOrder_whenStockInsufficient_throwsException() { ... }

References

  • docs/STYLE_GUIDE.md — 원칙 (Karpathy 4 + 동료 협업 + 정량)
  • docs/RED_FLAGS.md — 안티패턴
  • docs/LAYER_RULES.md — 레이어 규칙

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.