원클릭으로
unit-test
Create BLoC and Service unit tests for an existing feature - Deterministic, high-signal unit test generation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Create BLoC and Service unit tests for an existing feature - Deterministic, high-signal unit test generation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Create a new feature — implement a screen, add a page, scaffold a flow, implement an API spec (OpenAPI/Swagger), or build a new data layer + UI. Use for ANY prompt that mentions: feature, screen, page, API spec, swagger, openapi, implement, build from spec.
Create Golden tests for an existing feature - Deterministic, convention-compliant golden test generation for feature pages
| name | unit_test |
| description | Create BLoC and Service unit tests for an existing feature - Deterministic, high-signal unit test generation |
This skill guides the AI agent in creating unit tests for Flutter/Dart services, repositories, and BLoCs, adhering strictly to the established architecture and patterns.
To successfully execute this skill, the following inputs MUST be provided:
feature_profile or lib/feature_profile)Correctness > Coverage > Quantity
The agent must prefer not generating tests over generating low-value tests.
Before generating any test code, the agent MUST evaluate the target method.
if, switch, guards)return repository.method())response.items)DateTime.now())If uncertain, the agent MUST assume the code is NOT test-worthy.
If the method does not pass the AI Test Gate, the agent MUST respond with:
This [service/method] does not require unit tests.
Reason: [One sentence explaining why it has no business logic.]
What would need to change for tests to be valuable: [One sentence describing what logic would justify tests.]
The agent MUST NOT generate:
Tests must reside in the test/ directory, mirroring the structure of lib/.
main()setUp()defineWhen()group() blocks| Test Type | Location |
|---|---|
| BLoC tests | test/feature_<name>/blocs/<name>_bloc_test.dart |
| Service tests | test/feature_<name>/services/<name>_service_test.dart |
| Repository tests | test/base/repositories/<name>_repository_test.dart |
test/mocks/stubs.dartThis includes:
const or final values inside test filesIf new data is needed, it MUST be added to stubs.dart.
Mocks MUST:
createXMock())Mocks MUST NOT:
If a required mock does not exist, the agent MUST:
build_runner will be executed externallyIf the same mocked method is stubbed in more than one test, the agent MUST:
defineWhen() helperInline stubbing in this case is always invalid.
The agent MUST place defineWhen():
main()setUp()group('{ServiceName} {methodName} tests', () { ... });
test('test {ServiceName} {methodName} - {scenario}', () { ... });
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:rx_bloc/rx_bloc.dart';
import 'package:rx_bloc_test/rx_bloc_test.dart';
import '../../base/common_blocs/coordinator_bloc_mock.dart';
import '../../mocks/stubs.dart';
import '<bloc_name>_bloc_test.mocks.dart';
@GenerateMocks([
MyFeatureService,
])
void main() {
late MyFeatureService service;
late CoordinatorBlocType coordinatorBloc;
late CoordinatorBlocStates coordinatorBlocStates;
void defineWhen({List<MyDomainModel>? items}) {
items ??= Stubs.mockList;
when(service.fetchData())
.thenAnswer((_) => Stream.value(items!));
when(coordinatorBlocStates.onItemUpdated)
.thenAnswer((_) => Stream.value(Result.success(Stubs.mockModel)));
}
MyFeatureBloc buildBloc() => MyFeatureBloc(
service,
coordinatorBloc,
);
setUp(() {
service = MockMyFeatureService();
coordinatorBlocStates = coordinatorStatesMockFactory();
coordinatorBloc = coordinatorBlocMockFactory(states: coordinatorBlocStates);
when(coordinatorBloc.states).thenReturn(coordinatorBlocStates);
});
group('MyFeatureBloc fetchData tests', () {
rxBlocTest<MyFeatureBlocType, Result<List<MyDomainModel>>>(
'test MyFeatureBloc fetchData - success',
build: () async {
defineWhen(items: Stubs.mockList);
return buildBloc();
},
act: (bloc) async => bloc.events.fetchData(),
state: (bloc) => bloc.states.dataResult,
expect: [
Result.success([]),
Result.loading(),
Result.success(Stubs.mockList),
],
);
rxBlocTest<MyFeatureBlocType, Result<List<MyDomainModel>>>(
'test MyFeatureBloc fetchData - error',
build: () async {
when(service.fetchData()).thenThrow(Stubs.error);
return buildBloc();
},
act: (bloc) async => bloc.events.fetchData(),
state: (bloc) => bloc.states.dataResult,
expect: [
Result.success([]),
Result.loading(),
Result.error(Stubs.error),
],
);
});
}
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import '../../mocks/mock_repositories.dart';
import '../../mocks/stubs.dart';
void main() {
late MyFeatureRepository repository;
late MyFeatureService service;
void defineWhen({List<MyDomainModel>? items}) {
items ??= Stubs.mockList;
when(repository.fetchData()).thenAnswer((_) async => items!);
}
setUp(() {
repository = createMyFeatureRepositoryMock();
service = MyFeatureService(repository);
});
group('MyFeatureService filterActiveItems tests', () {
test('test MyFeatureService filterActiveItems - filters inactive items', () async {
defineWhen(items: Stubs.mixedItemsList);
final result = await service.filterActiveItems();
expect(result.length, equals(Stubs.activeItemsCount));
expect(result.every((item) => item.isActive), isTrue);
});
test('test MyFeatureService filterActiveItems - returns empty for no active items', () async {
defineWhen(items: Stubs.inactiveItemsList);
final result = await service.filterActiveItems();
expect(result, isEmpty);
});
});
}
The following actions are always invalid:
@GenerateMocks in test files (use centralized mock files)when() stub across multiple testsIf the agent cannot clearly articulate:
Then the agent MUST NOT generate tests.
Coverage percentage is irrelevant.
A service with 0% coverage is acceptable if it contains no business logic.
Generating placeholder tests to increase coverage is forbidden.
Run build_runner to generate mock files:
dart run build_runner build --delete-conflicting-outputs
Run tests:
flutter test test/feature_<name>/
By following these architecture and testing guidelines strictly, you will produce seamless, clean, scalable unit tests fully integrated into the pipeline.