본문으로 건너뛰기
Skillpedia
테스트40k · #7256

java-junit

하는 일

이 도구는 JUnit 5를 사용해 Java 코드의 테스트를 작성하도록 돕습니다. 일반적인 기능에 대한 모범 사례를 가르치고, 여러 입력 데이터를 사용하는 테스트도 다룹니다.

사용하는 경우

  • ✓Java 코드가 올바르게 작동하는지 확인하고 싶을 때.
  • ✓프로젝트의 자동 테스트 작성을 배울 때.
  • ✓코드 반복 없이 여러 입력값으로 코드를 테스트하고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/java-junit/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/java-junit/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“합계 함수가 2+2가 4인지 확인하는 테스트를 어떻게 작성하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

도구는 테스트를 정리하고, 설정과 실행을 위해 특정 JUnit 어노테이션을 사용하는 방법, 예상 결과가 달성되었는지 확인하는 방법을 설명합니다. 또한 여러 시나리오로 코드를 테스트하기 위해 다양한 데이터 소스를 사용하는 방법도 보여 줍니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

JUnit 5+ Best Practices

Your goal is to help me write effective unit tests with JUnit 5, covering both standard and data-driven testing approaches.

Project Setup

  • Use a standard Maven or Gradle project structure.
  • Place test source code in src/test/java.
  • Include dependencies for junit-jupiter-api, junit-jupiter-engine, and junit-jupiter-params for parameterized tests.
  • Use build tool commands to run tests: mvn test or gradle test.

Test Structure

  • Test classes should have a Test suffix, e.g., CalculatorTest for a Calculator class.
  • Use @Test for test methods.
  • Follow the Arrange-Act-Assert (AAA) pattern.
  • Name tests using a descriptive convention, like methodName_should_expectedBehavior_when_scenario.
  • Use @BeforeEach and @AfterEach for per-test setup and teardown.
  • Use @BeforeAll and @AfterAll for per-class setup and teardown (must be static methods).
  • Use @DisplayName to provide a human-readable name for test classes and methods.

Standard Tests

  • Keep tests focused on a single behavior.
  • Avoid testing multiple conditions in one test method.
  • Make tests independent and idempotent (can run in any order).
  • Avoid test interdependencies.

Data-Driven (Parameterized) Tests

  • Use @ParameterizedTest to mark a method as a parameterized test.
  • Use @ValueSource for simple literal values (strings, ints, etc.).
  • Use @MethodSource to refer to a factory method that provides test arguments as a Stream, Collection, etc.
  • Use @CsvSource for inline comma-separated values.
  • Use @CsvFileSource to use a CSV file from the classpath.
  • Use @EnumSource to use enum constants.

Assertions

  • Use the static methods from org.junit.jupiter.api.Assertions (e.g., assertEquals, assertTrue, assertNotNull).
  • For more fluent and readable assertions, consider using a library like AssertJ (assertThat(...).is...).
  • Use assertThrows or assertDoesNotThrow to test for exceptions.
  • Group related assertions with assertAll to ensure all assertions are checked before the test fails.
  • Use descriptive messages in assertions to provide clarity on failure.

Mocking and Isolation

  • Use a mocking framework like Mockito to create mock objects for dependencies.
  • Use @Mock and @InjectMocks annotations from Mockito to simplify mock creation and injection.
  • Use interfaces to facilitate mocking.

Test Organization

  • Group tests by feature or component using packages.
  • Use @Tag to categorize tests (e.g., @Tag("fast"), @Tag("integration")).
  • Use @TestMethodOrder(MethodOrderer.OrderAnnotation.class) and @Order to control test execution order when strictly necessary.
  • Use @Disabled to temporarily skip a test method or class, providing a reason.
  • Use @Nested to group tests in a nested inner class for better organization and structure.
자주 묻는 질문

단위 테스트란 무엇인가요?

코드의 작은 부분(보통 함수나 메서드)을 단독으로 검사해 예상대로 작동하는지 확인하는 테스트입니다.

'데이터 기반' 테스트란 무엇인가요?

같은 테스트 로직을 다른 입력 및 출력 데이터 집합으로 여러 번 실행하는 테스트입니다. 코드 반복을 피할 수 있습니다.

이것을 쓰려면 Java를 많이 알아야 하나요?

기본적인 Java 지식이 있으면 도움이 되지만, 이 도구는 초보자도 이해할 수 있도록 테스트 개념을 명확히 설명하도록 설계되었습니다.

상세 정보

작성자의 원본 설명

Get best practices for JUnit 5 unit testing, including data-driven tests

repo: github/awesome-copilot

인기도

GitHub 스타
40k
순위
#7256
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬