# Write Allra Backend Tests

Backend teams need consistent Spring test choices and readable Java test structure. This skill guides helper selection, Fixture Monkey setup, Given-When-Then layout, AssertJ assertions, and Mockito patterns.

## Install

```bash
npx skillstore add allra-fintech/allra-test-writing
```

## Metadata

- - Slug: allra-fintech-allra-test-writing
- - Version: 1.0.0
- - Author: Allra-Fintech
- - GitHub username: Allra-Fintech
- - License: MIT
- - Repository: https://github.com/Allra-Fintech/allra-ai-skills/tree/main/backend-plugin/skills/test-writing
- - Ref: main
- - Supported tools: Claude, Codex, Claude Code
- - Risk level: low
- - Risk factors: external\_commands
- - Quality score: 77
- - Quality tier: bronze
- - Public page: https://skillstore.pages.dev/skills/allra-fintech-allra-test-writing
- - Manifest: https://skillstore.pages.dev/api/skills/allra-fintech-allra-test-writing/manifest

## Capabilities

- Selects Allra test helper types for integration, repository, controller, Redis, service, and domain tests.
- Explains when to choose MockingUnitTest instead of IntegrationTest for Spring services.
- Structures Java tests with Given-When-Then sections and descriptive display names.
- Guides Fixture Monkey usage for generated test data and field overrides.
- Shows AssertJ and Mockito patterns for assertions, mocks, exceptions, and verification.
- Provides Gradle and Maven examples for running all tests, tagged tests, and specific test classes.

## Use Cases

- Create Service Unit Tests: Write fast service tests with Mockito, AssertJ, and clear Given-When-Then sections.
- Standardize Test Review: Review whether new tests use the right helper type and avoid excessive integration tests.
- Improve Repository Coverage: Plan repository and QueryDSL tests that verify database behavior and important constraints.

## Prompt Templates

### Choose a Test Type

```
I need to test this Java Spring feature: [describe feature]. Choose the Allra test helper and explain why.
```

### Draft a Unit Test

```
Write a JUnit 5 service unit test for [class and method]. Use Mockito, AssertJ, and Given-When-Then comments.
```

### Convert Integration to Mock Test

```
Review this integration test and decide if it can become a MockingUnitTest. Keep only necessary integration coverage.
```

### Design a Test Strategy

```
Create a test strategy for this Spring workflow: [workflow]. Separate controller, service, repository, and integration tests.
```

## Limitations

- The guidance assumes Java 17, Spring Boot 3.2, JUnit 5, AssertJ, and Mockito.
- Allra helper classes may not exist in every project and may need local equivalents.
- The skill does not inspect runtime coverage or execute tests by itself.
- Examples must be adapted to the application domain, package names, and repository APIs.

## Best Practices

- Start with MockingUnitTest for service logic unless transaction, money, or multi-table behavior requires integration coverage.
- Use Given-When-Then sections and display names that explain the business scenario.
- Mock external systems in integration tests and verify internal database state only when needed.

## Anti Patterns

- Using IntegrationTest for simple validation, calculation, or single-repository logic.
- Creating random test data without overriding fields that drive the expected result.
- Writing assertions that only check non-null results without verifying business outcomes.

## Security Audit

- - Safe to publish: true
- - Audited at: 2026-06-28T08:13:09.346\+00:00
- - Summary: Static analysis reported many external command and blocker patterns, but review found they are markdown backticks, Java examples, and test documentation. No prompt injection, credential access, network exfiltration, or malicious behavior was found. The skill includes benign Gradle and Maven test command examples, so external command risk is retained as a low-risk publication warning.

## Stats

- - Views: 257
- - Downloads: 6
- - Favorites: 0
- - Popularity score: 0
