| name | behavior-analyzer-tester |
| description | Analyzes code behavior and generates comprehensive GIVEN-WHEN-THEN unit tests with vanilla JUnit5. Use when generating tests, analyzing behavior for test coverage, creating unit tests for Fakt components, or writing tests for new or modified code. Make sure to use this skill whenever new tests need to be written — it ensures BDD naming compliance, proper test isolation, and coverage of edge cases that are easy to overlook. |
| allowed-tools | Read, Write, Edit, Grep, Glob, Bash, TaskCreate, TaskUpdate |
Behavior Analyzer & Test Generator
Analyzes code to identify all behaviors and generates complete GIVEN-WHEN-THEN test coverage.
Instructions
1. Identify Target File
Extract file path from conversation:
- "analyze UserService.kt", "generate tests for PaymentProcessor"
- If missing, ask: "Which file would you like me to analyze?"
2. Deep Behavior Analysis
Read the target file and analyze:
2.1 Public API — Find all public methods, properties, their signatures, parameters, return types.
2.2 Edge Cases — Nullable types, empty collections, boundary values.
2.3 Error Handling — Exceptions thrown, require/check validation, error conditions.
2.4 State Management — Mutable properties, state transitions, side effects.
2.5 Async/Concurrency — Suspend functions, coroutine scopes.
Create behavior map:
## Behaviors Found in {FileName}
### Public API ({X} methods, {Y} properties):
1. `methodName(param: Type): ReturnType` - Description
### Edge Cases:
- Null handling: {scenarios}
- Empty collections: {scenarios}
### Error Scenarios:
- Throws XException when {condition}
### State Transitions:
- {initial} → {action} → {new state}
3. Check Existing Tests
Glob pattern="**/*{ClassName}Test.kt"
4. Generate Test Cases
For each behavior, create a GIVEN-WHEN-THEN scenario:
Prioritize:
- HIGH: Public API, critical paths, error handling
- MEDIUM: Edge cases, state transitions
- LOW: Additional validations
Create tasks for tracking:
TaskCreate: each test case as a separate task
5. Implement Tests
Test file template:
package {package_name}
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import kotlin.test.*
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class {ClassName}Test {
@Test
fun `GIVEN valid input WHEN processing THEN returns expected result`() = runTest {
val sut = ClassName()
val result = sut.process(input)
assertEquals(expected, result)
}
@Test
fun `GIVEN null input WHEN processing THEN throws IllegalArgumentException`() {
val sut = ClassName()
assertFailsWith<IllegalArgumentException> {
sut.process(null)
}
}
}
For each test:
- Mark task as in_progress
- Implement the test
- Compile:
./gradlew compileTestKotlin
- Run:
./gradlew test --tests "{ClassName}Test.{testMethodName}"
- Mark task as completed when passing
6. Validate Coverage & Compliance
Grep pattern='fun \`should' {test_file}
./gradlew spotlessApply
./gradlew test --tests "{ClassName}Test"
7. Summary Report
BEHAVIOR ANALYSIS & TEST GENERATION COMPLETE
Target: {file_path}
Tests Generated: {count} (happy: {n}, edge: {n}, error: {n}, async: {n})
Coverage: {methods_covered}/{total} methods
All tests pass: yes/no
Compliance: GIVEN-WHEN-THEN ✅ | Vanilla assertions ✅ | No mocks ✅
Related Skills
bdd-test-runner — Run and validate generated tests
compilation — Validate generated tests compile