Agent skill
Java Testing Standards
Modern testing practices using JUnit 5, AssertJ, and Mockito.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/testing-hoangnguyen0403-agent-skills-standar-2
Metadata
Additional technical details for this skill
- labels
-
java testing junit assertj mockito
- triggers
-
{ "files": [ "**/*Test.java", "**/*IT.java" ], "keywords": [ "test", "assert", "mock", "verify", "junit" ] }
SKILL.md
Java Testing Standards
Priority: P0 (CRITICAL)
High-reliability testing using JUnit 5 and fluent assertions.
Implementation Guidelines
- Framework: Use JUnit 5 (Jupiter). Avoid JUnit 4.
- Assertions: Use AssertJ (
assertThat) over JUnitassertEquals. It's more readable and provides better error messages. - Naming:
MethodName_StateUnderTesting_ExpectedBehavioror@DisplayName("Should return X when Y"). - Parameterized: Use
@ParameterizedTestwith@ValueSourceor@MethodSourcefor data-driven tests. - Mocking: Use Mockito. Strictly limit mocking to external dependencies (I/O). Do not mock data objects.
- Integration: Use Testcontainers for real databases/brokers in integration tests (
*IT.java). - Visibility: Test classes and methods can be package-private in JUnit 5 (no
publicneeded).
Anti-Patterns
- Logic in Tests: Tests should be declarative. No loops or heavy if/else.
System.out: Never print in tests. Use Assertions.- Legacy Assertions: Avoid
assertTrue(a == b). UseassertThat(a).isEqualTo(b). - Global State: Tests must be isolated. No strict dependency on execution order.
Code
For a full Mockito + AssertJ test class template:
references/junit-template.md
// JUnit 5 + AssertJ
import static org.assertj.core.api.Assertions.assertThat;
class UserServiceTest {
@Test
@DisplayName("Should detect active users")
void shouldDetectActiveUsers() {
// Arrange
var user = new User("id", "active");
// Act
boolean isActive = service.isActive(user);
// Assert
assertThat(isActive)
.as("Check active user status")
.isTrue();
}
}
Related Topics
best-practices | quality-assurance
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?