Skip to content

Commit

Permalink
Update kotest-property-extensions docs
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed Apr 17, 2024
1 parent e2a4499 commit 97ff39e
Showing 1 changed file with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Kotlin-faker `kotest-property` and `kotest-property-ksp` artifacts provide faker
- ① add the ksp plugin (You can check the latest version in their [releases](https://github.com/google/ksp/releases/).)
- ② add the core `kotlin-faker` dependency to the test classpath
- ③ add the `testImplementation` dependency for the `kotest-property` extension
- ④ add the `kspTest` dependency for the `kotest-property-ksp` extension
- This will generate the code for test sources. If you're using kotlin-faker for something other than testing (e.g. data anonymization) and want to generate extension code for main source instead, use `ksp` configuration for this dependency.
- ④ add the `kspTest` dependency for the `kotest-property` and `kotest-property-ksp` extensions
- This will generate the code for test sources. If you're using kotlin-faker for something other than testing (e.g. data anonymization) and want to generate extension code for main source instead, use `ksp` configuration for this dependency.
- ⑤ the core `kotlin-faker` dependency also needs to be added to `kspTest` configuration

{% tabs %}
Expand All @@ -41,6 +41,7 @@ plugins {
dependencies {
testImplementation("io.github.serpro69:kotlin-faker:$fakerVersion") //
testImplementation("io.github.serpro69:kotlin-faker-kotest-property:$fakerExtVersion") //
kspTest("io.github.serpro69:kotlin-faker-kotest-property:$fakerVersion") //
kspTest("io.github.serpro69:kotlin-faker-kotest-property-ksp:$fakerExtVersion") //
kspTest("io.github.serpro69:kotlin-faker:$fakerVersion") //
}
Expand Down Expand Up @@ -89,6 +90,33 @@ dependencies {
{% endfilter %}
{% endwarn %}

<br>

{% warn %}
{% filter compileAs('md') %}
Note that if you're using {{ anchor(title='Faker BOM', collectionType='wiki', collectionId='', itemId='Kotlin-faker BOM') }} to manage faker versions, `ksp` and `kspTest` configurations are not able to pick up versions from the bom, and they (versions) need to be declared explicitly for these configurations.

See more in the [ksp/issues/1884](https://github.com/google/ksp/issues/1844).

```diff
dependencies {
testImplementation(platform("io.github.serpro69:kotlin-faker-bom:2.0.0-rc.4"))
testImplementation("io.github.serpro69:kotlin-faker") // uses version from the bom
testImplementation("io.github.serpro69:kotlin-faker-kotest-property") // uses version from the bom
- kspTest("io.github.serpro69:kotlin-faker-kotest-property") // CAN'T use version from the bom
- kspTest("io.github.serpro69:kotlin-faker-kotest-property-ksp")
- kspTest("io.github.serpro69:kotlin-faker")
+ kspTest("io.github.serpro69:kotlin-faker-kotest-property:2.0.0-rc.1")
+ kspTest("io.github.serpro69:kotlin-faker-kotest-property-ksp:2.0.0-rc.1")
+ kspTest("io.github.serpro69:kotlin-faker:2.0.0-rc.4")
}
```

{% endfilter %}
{% endwarn %}

---

The plugin will generate [`Arb` generator](https://kotest.io/docs/proptest/property-test-generators.html) extensions for all specified faker classes and their data providers.

① Each `Faker` instance will have an `arb` property that provides access to standard faker data generators, but which return data wrapped in `Arb` instances.
Expand Down Expand Up @@ -219,6 +247,12 @@ it("should generate person with address") {
}
```

{% info %}
{% filter compileAs('md') %}
If you only need `randomClass` instance extension, it is sufficient to just add `"io.github.serpro69:kotlin-faker-kotest-property:$fakerExtVersion"` dependency to e.g. `testImplementation` configuration, as it is part of the library itself and is not auto-generated by KSP.
{% endfilter %}
{% endinfo %}

{% btc %}{% endbtc %}

<br>

0 comments on commit 97ff39e

Please sign in to comment.