Skip to content

Dogacel/kotest-property-protobuf

Repository files navigation

Kotest Protobuf Property Testing

Maven Central Version GitHub Release Date

Build codecov License Contributors Commits

Property testing extension for Protobuf using kotest-property. You can generate random protobuf messages using Arb.protobufMessage<...>() call and customize the generation properties.

Usage

Include the dependency inside build.gradle.kts.

dependencies {
    testImplementation("io.github.dogacel:kotest-property-protobuf:LATEST")
}

Use the Arb generators provided by the module to generate random protobuf classes.

import dogacel.kotest.ProtobufMessageArb.protobufMessage

class SampleProtobufTest : FunSpec({
    test("should convert without errors") {
        val settings = ProtobufMessageArbSettings(fieldPresenceProbability = 0.80)
        Arb.protobufMessage<FooMessage>(settings).forAll { protoMessage ->
            val sut = convert(protoMessage)
            // Do some validation
            sut.id == protoMessage.id && sut.name == (protoMessage.firstName + protoMessage.lastName)
        }
    }
})

For configuring the generation settings, check ProtobufMessageArbSettings class.

Roadmap

  • Allow generation of random protobuf messages.
  • Generate realistic well-known types. (I.e. generate timestamps in ±50 years)
  • Allow customizing generation settings per field.
  • Support protovalidate rules.

Releasing

Note

This section is applicable to official maintainers only.

  1. Update version under root build.gradle.kts.
  2. Make sure you set SONATYPE_USERNAME, SONATYPE_PASSWORD, GPG_SIGNING_KEY and GPG_SIGNING_PASSPHRASE.
  3. ./gradlew publishToSonatype
  4. ./gradlew findSonatypeStagingRepository closeSonatypeStagingRepository
  5. ./gradlew findSonatypeStagingRepository releaseSonatypeStagingRepository

For any errors, visit https://s01.oss.sonatype.org/#stagingRepositories.

Snapshots

After you release a -SNAPSHOT version, you need the following block to import it.

repositories {
    maven {
        this.url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
    }
}

Contribution

For starters, start by checking issues.

Linting can be done via

``./gradlew ktlintFormat

Building the whole project,

./gradlew build

Check coverage of the code,

./gradlew koverHtmlReport

Please feel free to open issues and PRs.

About

Property testing for protobuf messages using Kotest

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages