KVS TestSmith ๐ ๏ธ
Automatic Flutter test generation powered by static analysis.
A powerful, production-ready CLI tool that automatically generates Flutter unit tests, widget tests, and integration tests by deeply analyzing your Dart source code using the Dart Analyzer AST, and fully implementing working tests with local AI powered by DeepSeek Coder via Ollama.
Think of it as Rails generators, but for Flutter tests.
โจ Features
- ๐ Project Scanner: Recursively scans
lib/while intelligently ignoring generated files (.g.dart,.freezed.dart,.config.dart) and build directories. - ๐ณ AST Parsing: Uses
package:analyzerto accurately detectStatelessWidget,StatefulWidget, Services, Repositories, Controllers, BLoCs, and Cubits. - ๐ Folder Mirroring: Tests are generated in a structure that perfectly mirrors your
lib/directory inside yourtest/directory. - ๐งช Smart Widget Tests: Automatically generates
testWidgets()withpumpWidget()and aMaterialAppwrapper. - ๐ฌ Smart Unit Tests: Generates
group()+test()stubs implementing the AAA pattern (Arrange, Act, Assert) for every public method. - ๐ค AI Test Implementation (Local): Automatically implement full working test files (bypassing stubs) using local Ollama (deepseek-coder) with intelligent UI Element extraction from your AST.
- ๐ญ Mock Generation: Automatically generates
mocktailmock classes inline for your services. - ๐ Watch Mode: Watches
lib/and auto-generates tests live as you create or modify files. - ๐ Coverage Support: Run
flutter test --coverageand get a parsed terminal summary of lines covered.
๐ฆ Installation
To use the CLI globally from anywhere on your machine:
dart pub global activate kvs_testsmith
Or, add it as a dev dependency to your specific Flutter project:
dev_dependencies:
kvs_testsmith: ^1.0.0
๐ Usage
Run the tool from the root of your Flutter project.
Generate all missing tests
kvs_testsmith generate
Advanced Generation Options
# Generate only widget tests
kvs_testsmith generate --widgets
# Generate only unit tests
kvs_testsmith generate --unit
# Generate only for files that don't already have tests
kvs_testsmith generate --only-missing
# Combine flags
kvs_testsmith generate --unit --only-missing
Watch Mode
Leave this running in a terminal. As you add or modify Dart files in your lib/ directory, TestSmith will automatically generate tests for them.
kvs_testsmith watch
๐ค AI Test Implementation (DeepSeek Coder + Ollama)
KVS TestSmith can leverage a local AI to fully implement your interaction test files instead of just generating structural AAA stubs. The orchestrator will parse your AST, detect interactive UI elements (like ElevatedButton, TextField, GestureDetector) and pipe them to the local LLM.
Ollama Setup Instructions
- Download and install Ollama on your machine.
- Open your terminal and securely pull the underlying coding model by running:
ollama run deepseek-coder - Once Ollama is active locally, you can utilize the TestSmith AI feature:
kvs_testsmith generate --ai
Coverage Report
Runs your test suite with coverage enabled and prints a clean summary to the terminal.
kvs_testsmith coverage
๐๏ธ How It Works (Examples)
KVS TestSmith reads your code structure and generates tailored tests.
1. Widget Code โ Widget Test
If you have a widget at lib/features/auth/ui/login_page.dart:
// Generated by TestSmith at test/features/auth/ui/login_page_test.dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:my_app/features/auth/ui/login_page.dart';
void main() {
group('LoginPage', () {
testWidgets('renders correctly', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: const LoginPage(),
),
);
expect(find.byType(LoginPage), findsOneWidget);
});
});
}
2. Service/Repository Code โ Unit Test
If you have a repository at lib/features/auth/data/auth_repository.dart with a login() method:
// Generated by TestSmith at test/features/auth/data/auth_repository_test.dart
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:my_app/features/auth/data/auth_repository.dart';
class MockAuthRepository extends Mock implements AuthRepository {}
void main() {
group('AuthRepository', () {
late AuthRepository sut; // System Under Test
setUp(() {
sut = AuthRepository();
});
test('should be instantiated', () {
expect(sut, isNotNull);
});
// TestSmith detected your 'login' method!
test('login works correctly', () {
// TODO: Arrange
// TODO: Act
// final result = sut.login();
// TODO: Assert
// expect(result, expectedValue);
});
});
}
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for details on how to set up the project and submit pull requests.
If you find a bug or have a feature request, please open an issue.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ for the Flutter community by the KVS TestSmith Maintainers.
flutter_test_smith
Libraries
- ai/ai_test_generator
- ai/ollama_client
- ai/prompt_builder
- core/logger
- core/path_mapper
- core/scanner
- generators/mock_generator
- generators/test_smith_orchestrator
- generators/unit_test_generator
- generators/widget_test_generator
- kvs_testsmith
- KVS TestSmith โ Automatic Flutter Test Generation
- parser/dart_ast_parser
- parser/service_detector
- parser/ui_element_detector
- parser/widget_detector
- templates/unit_test_template
- templates/widget_test_template
- utils/file_writer
- utils/import_resolver