基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-java --skill java-testing命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Master Java concurrency - threads, executors, locks, CompletableFuture, virtual threads
Containerize Java applications - Dockerfile optimization, JVM settings, security
Master core Java programming - syntax, OOP, collections, streams, and exception handling
| name | java-testing |
| description | Test Java applications - JUnit 5, Mockito, integration testing, TDD patterns |
| sasmp_version | 1.3.0 |
| version | 3.0.0 |
| bonded_agent | 04-java-testing |
| bond_type | PRIMARY_BOND |
| allowed-tools | Read, Write, Bash, Glob, Grep |
| parameters | {"test_type":{"type":"string","enum":["unit","integration","e2e","contract"],"description":"Type of test to create"},"framework":{"type":"string","default":"junit5","enum":["junit5","testng"],"description":"Testing framework"}} |
Write comprehensive tests for Java applications with modern testing practices.
This skill covers Java testing with JUnit 5, Mockito, AssertJ, and integration testing with Spring Boot Test and Testcontainers. Includes TDD patterns and test coverage strategies.
Use when you need to:
// Unit Test with Mockito
@ExtendWith(MockitoExtension.class)
class UserServiceTest {
@Mock
private UserRepository userRepository;
@InjectMocks
private UserService userService;
@Test
@DisplayName("Should find user by ID")
void shouldFindUserById() {
// Given
User user = new User(1L, "John");
given(userRepository.findById(1L)).willReturn(Optional.of(user));
// When
Optional<User> result = userService.findById(1L);
// Then
assertThat(result)
.isPresent()
.hasValueSatisfying(u ->
assertThat(u.getName()).isEqualTo("John"));
then(userRepository).should().findById(1L);
}
}
// Parameterized Test
@ParameterizedTest
@CsvSource({
"valid@email.com, true",
"invalid-email, false",
"'', false"
})
void shouldValidateEmail(String email, boolean expected) {
assertThat(validator.isValid(email)).isEqualTo(expected);
}
// Integration Test with Testcontainers
@Testcontainers
@SpringBootTest
class OrderRepositoryIT {
@Container
static PostgreSQLContainer<?> postgres =
new PostgreSQLContainer<>();
{
registry.add(, postgres::getJdbcUrl);
registry.add(, postgres::getUsername);
registry.add(, postgres::getPassword);
}
OrderRepository repository;
{
repository.save( (, ));
assertThat(saved.getId()).isNotNull();
}
}
{
MockMvc mockMvc;
UserService userService;
Exception {
given(userService.findById())
.willReturn(Optional.of( (, )));
mockMvc.perform(get())
.andExpect(status().isOk())
.andExpect(jsonPath().value());
}
}
public class UserTestBuilder {
private Long id = 1L;
private String name = "John Doe";
private String email = "john@example.com";
private boolean active = true;
public static UserTestBuilder aUser() {
return new UserTestBuilder();
}
public UserTestBuilder withName(String name) {
this.name = name;
return this;
}
public UserTestBuilder inactive() {
this.active = false;
return this;
}
public User build() {
return new User(id, name, email, active);
}
}
// Usage
User user = aUser().withName().inactive().build();
<!-- JaCoCo configuration -->
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
| Problem | Cause | Solution |
|---|---|---|
| Mock not working | Missing @ExtendWith | Add MockitoExtension |
| NPE in test | Mock not initialized | Check @InjectMocks |
| Flaky test | Shared state | Isolate test data |
| Context fails | Missing bean | Use @MockBean |
□ Run single test in isolation
□ Check mock setup matches invocation
□ Verify @BeforeEach setup
□ Review @Transactional boundaries
□ Check for shared mutable state
Skill("java-testing")
java-testing-advanced - Advanced patternsjava-spring-boot - Spring test slices