Faketory
A generic fake factory for Plain Old Java/Kotlin Objects
Install / Use
/learn @helloseyedjafari/FaketoryREADME
Faketory

A generic fake factory for Java/Kotlin POJO/POKO.
This library can create an instance of your classes. The idea behind is to avoid creating instances of DTOs/Entities/Domain objects manually.
The main usecase is in tests. creating objects for tests is usually very time consuming and can deviate our attention from the tests. Changes in our POJO/POKOs will cause refactoring in our tests, even if we are not touching that part. With Faketory you can focus on your test.
Another mocking library?
Faketory is not a mocking library, because it creates real objects and does not control their behaviour. Also, it can not create abstract classes and interfaces (as they are usually not our real domain objects).
Usage
Import the dependency:
testImplementation "com.worldsnas:faketory:$latestVersion"
Start creating objects:
Kotlin
val objectOfYourClass = Faketory.create<YourClass>()
Java
TypeReference<YourClass> reference = new TypeReference<YourClass>() {};
YourClass objectOfYourClass = Faketory.create(reference, config);
For more sample please check test directory.
Important:
This library is mainly meant for tests
Configuration
This library is highly customizable. With the help of the Config object, you can customize every step of the object creation process. The default behavior is configured with static fields and generators to avoid extra object creation and speed up the whole instance creation.
You can override the default behavior in two ways:
- Setting a new
Configto staticFaketory.defaultConfigfield. You can use Kotlincopyfunction to avoid passing all the parameters:
Faketory.defaultConfig = Faketory.defaultConfig.copy(
useDefaultConstructor = false,
setNull = false,
useSubObjectsForSealeds = false
)
This approach is good to setup Faketory once (for example: in @BeforeClass) and run all the tests with it.
- If you want more control for each test, you can pass your new
Configobject to theFaketory.createfunction:
val actual = Faketory.create<ClassWithDefault>(
Faketory.defaultConfig.copy(useDefaultConstructor = true)
)
Important:
Avoid using heavy and time-consuming generators as they will increase your test time
Inspired by
Python Model Bakery
Contribution
I'm more than happy to discuss, so:
- Create issues
- Send PRs
Any contribution is more than welcome
License
Faketory is MIT-licensed.
Related Skills
gh-issues
342.5kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
node-connect
342.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
85.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
85.3kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
