junit-testing
БесплатноБез исполняемых скриптовНе проверенJUnit 6 testing patterns for Xeres including Mockito with constructor injection, test fixtures via *Fakes.java classes, and AssertJ assertions.
от zapek★ 224 звезды на GitHubОб этом скилле
JUnit Testing Patterns for Xeres
Test Structure
- Location:
src/test/java/mirrors main source structure - Naming:
*Test.javasuffix - Framework: JUnit 6 with Jupiter
Running the tests
When you run the tests with Gradle, add --no-configuration-cache --no-configure-on-demand because there's often issue with caching.
Mockito Extension Pattern
@ExtendWith(MockitoExtension.class)
class ContactServiceTest
{
@Mock
private ProfileService profileService;
@InjectMocks
private ContactService contactService;
@Test
void getContacts_ShouldReturnCombinedList()
{
when(profileService.getProfiles()).thenReturn(List.of());
var result = contactService.getContacts();
assertTrue(result.isEmpty());
}
}
Key Points
- Use constructor injection (Mockito injects via
@InjectMocks) @Mockcreates a mock,@Spycreates a partial mockwhen(...).thenReturn(...)for stubbingverify(...).method()for interaction testing- Prefer JUnit assertions:
assertTrue(...)but it's also possible to use assertJ for more complex cases
Test Fixtures
Use *Fakes.java in common/src/testFixtures/java/io/xeres/:
public final class ProfileFakes
{
private ProfileFakes()
{
throw new UnsupportedOperationException("Utility class");
}
public static Profile createProfile()
{
return createProfile(1L, "Test Profile");
}
public static Profile createProfile(long id, String name)
{
var profile = new Profile();
profile.setId(id);
profile.setName(name);
return profile;
}
public static Profile createOwnProfile()
{
var profile = createProfile();
profile.setOwn(true);
return profile;
}
}
- Use IdFakes to create GxsId or MsgId.
Assertion Examples
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;
@Test
void foobar()
{
assertNotNull(result);
assertEquals("Test", result.getName());
assertThat(list)
.hasSize(2)
.contains(profile1, profile2);
assertThatThrownBy(() -> service
.save(null))
.isInstanceOf(IllegalArgumentException.class);
}
Exception Testing
@Test
void save_WithNullProfile_ShouldThrow()
{
assertThatThrownBy(() -> contactService.save(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("Profile must not be null");
}
See Also
ui-testingskill for JavaFX controller testingarchunit-rulesskill for testing architecture rules
Установить junit-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл junit-testing?
JUnit 6 testing patterns for Xeres including Mockito with constructor injection, test fixtures via *Fakes.java classes, and AssertJ assertions.
Как установить скилл junit-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл junit-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic