https://github.com/matmoore/kotlin-test-factory
Kotlin library for creating test factories
https://github.com/matmoore/kotlin-test-factory
Last synced: about 1 year ago
JSON representation
Kotlin library for creating test factories
- Host: GitHub
- URL: https://github.com/matmoore/kotlin-test-factory
- Owner: MatMoore
- Created: 2023-04-20T07:43:26.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T08:20:08.000Z (about 3 years ago)
- Last Synced: 2025-02-08T12:47:10.929Z (over 1 year ago)
- Language: Kotlin
- Size: 68.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Test factory
Test factory lets you define factory classes for use in unit tests,
inspired by FactoryBot in ruby. Test factories provide default values
for constructing kotlin classes, so that you only have to specify things
that matter to your test.
This is an experimental learning project.
## Usage
### Defining test factories
Test factories should inherit from the TestFactory class like so:
```kotlin
class FooFactory: TestFactory(Foo::class) {
val bar = 123
val baz = "hello"
}
```
### Using test factories
In your tests you can now construct objects like this:
```kotlin
val foo = FooFactory().build()
```
This will call the primary constructor of the class with the values defined on the factory.
The constructor parameters can be arbitrarily overriden at the call site by creating an anonymous object that
subclasses the factory, e.g.
```kotlin
val foo = object : FooFactory() { override val bar = 2 }.build()
```