Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

junit-testing

БесплатноБез исполняемых скриптовНе проверен

JUnit 6 testing patterns for Xeres including Mockito with constructor injection, test fixtures via *Fakes.java classes, and AssertJ assertions.

zapekот zapek★ 224 звезды на GitHub

Об этом скилле

JUnit Testing Patterns for Xeres

Test Structure

  • Location: src/test/java/ mirrors main source structure
  • Naming: *Test.java suffix
  • 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)
  • @Mock creates a mock, @Spy creates a partial mock
  • when(...).thenReturn(...) for stubbing
  • verify(...).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-testing skill for JavaFX controller testing
  • archunit-rules skill for testing architecture rules
Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить junit-testing с