> java-testing
Modern testing practices using JUnit 5, AssertJ, and Mockito. Use when writing JUnit 5 tests, AssertJ assertions, or Mockito mocks in Java. (triggers: **/*Test.java, **/*IT.java, test, assert, mock, verify, junit)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/java-testing?format=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
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)