Fakt¶
Compile-time type-safe test fakes for Kotlin Multiplatform
Automate the fake-over-mock pattern. Fakt generates type-safe test doubles that eliminate boilerplate.
@Fake
interface Analytics {
fun track(event: String)
}
val fake = fakeAnalytics {
track { event -> println("Tracked: $event") }
}
Why Fakt?¶
- Manual fakes scale poorly - Each type needs custom tracking, config, or cleanup code
- Manual fakes rot over time - Behavior diverges from real implementations without compile-time warnings
- Mocks verify interactions, not behavior - Testing how dependencies are called, not what code achieves
- Mocks make refactoring painful - Tests break even when behavior stays correct
- Google explicitly prefers fakes - Lightweight, framework-free, and resilient to refactoring
- Compile-time generation solves both problems - Automated fakes that never drift from interfaces
✨ Features¶
- ✅ Zero boilerplate - Compiler generates type-safe fakes automatically at build time
- ✅ Never drift from real code - Interface changes cause compile errors, not silent bugs
- ✅ Test what matters - Verify outcomes (state) instead of implementation details (calls)
- ✅ Works everywhere - All KMP targets without reflection, zero production dependencies
- ✅ Smart defaults - Sensible behaviors for all types, configure only what you need
- ✅ Real code, not magic - Generated .kt files are readable, not bytecode magic
🚀 Getting Started¶
Quick Start:
- Getting Started - Install Fakt and create your first fake in 5 minutes
- Usage Guide - Core patterns and techniques
- Testing Patterns - Best practices for using fakes in tests
Usage Topics:
- Suspend Functions - Working with coroutines and async code
- Generics - Generic interfaces and type parameters
- Properties - Faking val and var properties
- Call Tracking - StateFlow-based reactive counters
Advanced Topics:
- Multi-Module Setup - Cross-module fakes with collector modules
- Configuration - Plugin configuration and log levels
- Performance - Build times, caching, and optimization
- Migration from Mocks - Migrating from MockK or Mockito
Reference:
- API Reference - Complete generated API documentation
- Limitations - Known limitations and workarounds
- Compatibility - Platform and version requirements
- FAQ - Frequently asked questions
- Troubleshooting - Common issues and solutions
🌐 Platform Support¶
Fakt works on all Kotlin Multiplatform targets without reflection: JVM, Android, iOS, macOS, Linux, Windows, JavaScript, WebAssembly, watchOS, tvOS.
Single-platform projects (JVM-only, Android-only) are fully supported.
Requirements¶
- Kotlin: 2.2.21+
- Gradle: 8.0+
- JVM: 11+
License¶
Fakt is licensed under the Apache License 2.0.
Copyright (C) 2025 Rodrigo Sicarelli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.