unit-tests-java
Installation
SKILL.md
Adding Unit Tests (Java)
Use this skill when the user requests the creation or update of unit tests in a Java project using JUnit 5, Mockito, and AssertJ. For other languages, use the unit-tests skill.
Instructions
Follow these steps to generate unit tests:
- Naming Convention: Name the test class
{ClassName}Test. Name methodsshould{Behavior}When{Condition}(camelCase). - Structure:
- Location:
src/test/java/mirroring the source package structure. - Use
// Given,// When,// Thenstyle comments in test methods. - NO OTHER COMMENTS/JAVADOCS: Do not add method-level or class-level Javadocs unless absolutely necessary.
- Location:
- Dependencies:
- Use
JUnit 5(@Test,@ExtendWith(MockitoExtension.class)). - Use
Mockitofor mocking (@Mock,@InjectMocks). - Use
AssertJfor assertions (assertThat()). - Implement
WithAssertionsinterface in the test class to avoid static imports for assertions.
- Use
- Select Pattern: Choose the appropriate testing pattern below based on the verification needs (Basic, Exception, Parameterized, etc.).