Agent skill

Unit Testing Patterns

by Hack23 in Hack23/cia

Implement JUnit 5, Mockito, and AssertJ patterns with 80%+ code coverage for CIA platform unit tests

Apache-2.0Auto-check passedTesting & QA

Install Unit Testing Patterns

skills CLI
$ npx skills add Hack23/cia --skill unit-testing-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Hack23/cia unit-testing-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Hack23/cia.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/unit-testing-patterns .claude/skills/unit-testing-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
unit-testing-patterns
GitHub stars
239
Token cost
~1.9k tokens
SKILL.md length
79 words
Files
1
Skills in repo
78
Repo updated
First seen
Licence
Apache-2.0

At a glance

Implement JUnit 5, Mockito, and AssertJ patterns with 80%+ code coverage for CIA platform unit tests

  • Tasks that involve Unit testing
  • SKILL.md covers Purpose, When to Use, JUnit 5 Patterns and Mockito Best Practices, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Tasks that involve Test coverage

What it does

Unit Testing Patterns is an agent skill from Hack23/cia. Implement JUnit 5, Mockito, and AssertJ patterns with 80%+ code coverage for CIA platform unit tests

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Testing & QA, covering Unit testing and Test coverage. It works with JUnit. The repository describes itself as: Citizen Intelligence Agency. Open-source intelligence platform analyzing Swedish political activities using AI and data visualization. Tracks politicians, government… The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Unit testing
  • Tasks that involve Test coverage

Example prompts

  • “/unit-testing-patterns”

What it can do on your machine

Read from SKILL.md and the folder at commit 6a9797b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are java and xml).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • junit.org
    • assertj.github.io

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Unit Testing Patterns loads about 1.9k tokens when it runs. Until then it costs about 31 tokens; SKILL.md has 79 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~31
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from Hack23/cia at commit 6a9797b, republished under its Apache-2.0 licence (© Hack23). 79 words, ~1,912 tokens.

Download SKILL.mdSave it as .claude/skills/unit-testing-patterns/SKILL.md (or your agent's skills folder).
name
unit-testing-patterns
description
Implement JUnit 5, Mockito, and AssertJ patterns with 80%+ code coverage for CIA platform unit tests
license
Apache-2.0

Unit Testing Patterns Skill

Purpose

Write effective, maintainable unit tests using JUnit 5, Mockito, and AssertJ that achieve 80%+ code coverage.

When to Use

  • ✅ Testing business logic in services
  • ✅ Testing data validation
  • ✅ Testing utility functions
  • ✅ Test-driven development (TDD)

JUnit 5 Patterns

Test Structure (AAA Pattern)
java
@ExtendWith(MockitoExtension.class)
class PoliticianServiceTest {
    
    @Mock
    private PoliticianRepository repository;
    
    @Mock
    private AuditLogger auditLogger;
    
    @InjectMocks
    private PoliticianService service;
    
    @Test
    @DisplayName("Should find politician by ID when exists")
    void shouldFindPoliticianById() {
        // Arrange
        String politicianId = "196401011234";
        Politician expected = new Politician(politicianId, "John", "Doe");
        when(repository.findById(politicianId)).thenReturn(Optional.of(expected));
        
        // Act
        Politician actual = service.findById(politicianId);
        
        // Assert
        assertThat(actual).isNotNull();
        assertThat(actual.getId()).isEqualTo(politicianId);
        assertThat(actual.getFirstName()).isEqualTo("John");
    }
    
    @Test
    @DisplayName("Should throw exception when politician not found")
    void shouldThrowExceptionWhenNotFound() {
        // Arrange
        String politicianId = "999999999999";
        when(repository.findById(politicianId)).thenReturn(Optional.empty());
        
        // Act & Assert
        assertThatThrownBy(() -> service.findById(politicianId))
            .isInstanceOf(ResourceNotFoundException.class)
            .hasMessageContaining("Politician not found");
    }
}
Parameterized Tests
java
@ParameterizedTest
@CsvSource({
    "196401011234, true",
    "999999999999, true",
    "12345, false",
    "abcdefghijkl, false",
    "'', false"
})
@DisplayName("Should validate Swedish personal ID format")
void shouldValidatePersonalIdFormat(String personalId, boolean expected) {
    assertThat(validator.isValidPersonalId(personalId)).isEqualTo(expected);
}

@ParameterizedTest
@ValueSource(strings = {"password", "12345678", "qwerty", "admin"})
@DisplayName("Should reject common passwords")
void shouldRejectCommonPasswords(String password) {
    assertThat(passwordValidator.isWeak(password)).isTrue();
}
Test Lifecycle
java
class DatabaseTest {
    
    @BeforeAll
    static void setupClass() {
        // Run once before all tests
        initializeTestDatabase();
    }
    
    @BeforeEach
    void setup() {
        // Run before each test
        clearDatabase();
    }
    
    @AfterEach
    void teardown() {
        // Run after each test
        rollbackTransaction();
    }
    
    @AfterAll
    static void teardownClass() {
        // Run once after all tests
        closeConnections();
    }
}

Mockito Best Practices

Stubbing
java
@Test
void shouldReturnCachedData() {
    // Stub method to return specific value
    when(cache.get("key")).thenReturn("value");
    
    // Stub with argument matchers
    when(repository.findByName(anyString())).thenReturn(new ArrayList<>());
    
    // Stub with custom answer
    when(service.process(any())).thenAnswer(invocation -> {
        String arg = invocation.getArgument(0);
        return arg.toUpperCase();
    });
    
    // Stub to throw exception
    when(repository.findById("invalid"))
        .thenThrow(new IllegalArgumentException("Invalid ID"));
}
Verification
java
@Test
void shouldLogAuditEvent() {
    // Arrange
    Politician politician = new Politician("123", "John", "Doe");
    
    // Act
    service.create(politician);
    
    // Verify method was called once
    verify(auditLogger).log(eq("CREATE_POLITICIAN"), any(Politician.class));
    
    // Verify exact number of calls
    verify(repository, times(1)).save(politician);
    
    // Verify never called
    verify(emailService, never()).sendNotification(any());
    
    // Verify no more interactions
    verifyNoMoreInteractions(auditLogger);
}
Argument Captors
java
@Test
void shouldSaveWithCorrectTimestamp() {
    ArgumentCaptor<Politician> captor = ArgumentCaptor.forClass(Politician.class);
    
    service.create(new Politician("123", "John", "Doe"));
    
    verify(repository).save(captor.capture());
    
    Politician saved = captor.getValue();
    assertThat(saved.getCreatedAt()).isCloseTo(
        LocalDateTime.now(),
        within(1, ChronoUnit.SECONDS)
    );
}

AssertJ Fluent Assertions

java
@Test
void shouldHaveCorrectProperties() {
    Politician politician = service.findById("123");
    
    // Fluent assertions
    assertThat(politician)
        .isNotNull()
        .hasFieldOrPropertyWithValue("firstName", "John")
        .hasFieldOrProperty("lastName")
        .extracting("party")
        .isEqualTo("S");
    
    // Collection assertions
    List<Politician> politicians = service.findAll();
    assertThat(politicians)
        .isNotEmpty()
        .hasSize(5)
        .extracting("firstName")
        .contains("John", "Jane")
        .doesNotContain("Invalid");
    
    // Exception assertions
    assertThatThrownBy(() -> service.delete("invalid"))
        .isInstanceOf(NotFoundException.class)
        .hasMessage("Politician not found")
        .hasNoCause();
}

Code Coverage

Target: 80% Line Coverage, 70% Branch Coverage
xml
<!-- pom.xml -->
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
                <rules>
                    <rule>
                        <element>BUNDLE</element>
                        <limits>
                            <limit>
                                <counter>LINE</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.80</minimum>
                            </limit>
                            <limit>
                                <counter>BRANCH</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.70</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

Test Organization

src/test/java/
└── com/hack23/cia/
    ├── service/
    │   ├── impl/
    │   │   ├── PoliticianServiceTest.java
    │   │   └── VotingAnalysisServiceTest.java
    │   └── api/
    │       └── PoliticianServiceIT.java (Integration tests)
    ├── util/
    │   ├── DateUtilsTest.java
    │   └── ValidationUtilsTest.java
    └── testfoundation/
        ├── TestDataFactory.java
        └── AbstractServiceTest.java

References

© Hack23, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/unit-testing-patterns of Hack23/cia.

Open the folder on GitHubat commit 6a9797b

Compare with similar skills

Unit Testing Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Unit Testing Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Unit Testing Patterns this skillHack23/cia239—~1.9kAutomated safety check: PassApache-2.0
TDD Guidealirezarezvani/claude-skills28k—~3.4kAutomated safety check: PassMIT
TDD GuideLeoYeAI/openclaw-master-skills2.2k—~1.4kAutomated safety check: PassMIT
Interval Guided Regression Test UpdateArabelaTso/Skills-4-SE253—~2.7kAutomated safety check: PassApache-2.0
Java Regression Test GeneratorArabelaTso/Skills-4-SE253—~4kAutomated safety check: PassApache-2.0
Test Oracle GeneratorArabelaTso/Skills-4-SE253—~3.5kAutomated safety check: PassApache-2.0

Similar skills

  • TDD Guide

    alirezarezvani/claude-skills

    Test-driven development skill for writing unit tests, generating test fixtures and mocks, analyzing coverage gaps, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, Vitest, and…

    28k GitHub stars~3.4k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • TDD Guide

    LeoYeAI/openclaw-master-skills

    Test-driven development skill for writing unit tests, generating test fixtures and mocks, analyzing coverage gaps, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, Vitest, and…

    2.2k GitHub stars~1.4k tokensUpdated 2 mo ago
    Testing & QAAuto-check passed
  • Automatically updates regression tests based on interval analysis to maintain coverage of key program intervals.

    253 GitHub stars~2.7k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • Java Regression Test Generator

    ArabelaTso/Skills-4-SE

    Automatically generate regression tests for Java codebases by analyzing changes between old and new code versions.

    253 GitHub stars~4k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • Test Oracle Generator

    ArabelaTso/Skills-4-SE

    Generates automated test oracles to verify correct software behavior.

    253 GitHub stars~3.5k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • Coverage Enhancer

    ArabelaTso/Skills-4-SE

    Analyze existing test suites and source code to suggest additional unit tests that improve test coverage.

    253 GitHub stars~4.4k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed

More from Hack23/cia

All 78 skills in this repo
  • WCAG 2.1 AA compliance, ARIA attributes, keyboard navigation, screen reader optimization for accessible political data platforms

    239 GitHub stars~2.7k tokensUpdated today
    Auto-check passed
  • Advanced chart types, D3.js/Vaadin Charts patterns, political data visualization, time series analysis

    239 GitHub stars~1.5k tokensUpdated today
    Auto-check passed
  • AI Governance

    Hack23/cia

    AI governance, EU AI Act compliance, OWASP LLM security, responsible AI practices for GitHub Copilot agents

    239 GitHub stars~1.4k tokensUpdated today
    Auto-check passed
  • API Integration

    Hack23/cia

    External API integration patterns, retry logic, circuit breakers, caching, rate limiting for government data APIs

    239 GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • AWS CloudWatch metrics, alarms, dashboards, log insights, and application monitoring for the CIA platform

    239 GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • AWS security best practices, VPC security, IAM, KMS, CloudTrail, GuardDuty for CIA platform deployment

    239 GitHub stars~2.3k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about Unit Testing Patterns

What does Unit Testing Patterns do?

Implement JUnit 5, Mockito, and AssertJ patterns with 80%+ code coverage for CIA platform unit tests. Unit Testing Patterns is an agent skill from Hack23/cia.

When should I use Unit Testing Patterns?

Unit Testing Patterns fits situations like: tasks that involve Unit testing; tasks that involve Test coverage.

How do I install Unit Testing Patterns in Claude Code?

Run `npx skills add Hack23/cia --skill unit-testing-patterns -a claude-code`. Or copy the skill folder (.github/skills/unit-testing-patterns in Hack23/cia) into .claude/skills/unit-testing-patterns in your project. Claude Code loads it when a task matches its description.

How do I install Unit Testing Patterns in Codex?

Run `npx skills add Hack23/cia --skill unit-testing-patterns -a codex`. Or copy the skill folder (.github/skills/unit-testing-patterns in Hack23/cia) into .agents/skills/unit-testing-patterns in your project. Codex loads it when a task matches its description.

Can I use Unit Testing Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Hack23/cia --skill unit-testing-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/unit-testing-patterns, .gemini/skills/unit-testing-patterns, .github/skills/unit-testing-patterns and .opencode/skills/unit-testing-patterns in your project.

What does Unit Testing Patterns need to run?

SKILL.md names no scripts, command-line tools or credentials: Unit Testing Patterns is instructions for the agent only.

Does Unit Testing Patterns access the network?

SKILL.md names 2 domains. As links in the text: junit.org and assertj.github.io. This is read from the text; nothing was executed.

Is Unit Testing Patterns safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Unit Testing Patterns use?

Unit Testing Patterns is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Unit Testing Patterns use?

About 1.9k tokens (SKILL.md is roughly 7.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Unit Testing Patterns?

Skills that share tags, products or a category with Unit Testing Patterns: TDD Guide (alirezarezvani/claude-skills, 28k stars), TDD Guide (LeoYeAI/openclaw-master-skills, 2.2k stars), Interval Guided Regression Test Update (ArabelaTso/Skills-4-SE, 253 stars) and Java Regression Test Generator (ArabelaTso/Skills-4-SE, 253 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Unit Testing Patterns?

Hack23 (a GitHub organization) maintains it in Hack23/cia, which has 239 GitHub stars. The repository holds 78 skills in this directory. The repository was last updated on October 6, 2026.

Source: Hack23/cia on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.