How to use LabelsReporter class of io.kotest.property.classifications package

Best Kotest code snippet using io.kotest.property.classifications.LabelsReporter

config.kt

Source:config.kt Github

copy

Full Screen

1package io.kotest.property2import io.kotest.common.ExperimentalKotest3import io.kotest.mpp.atomics.AtomicProperty4import io.kotest.mpp.sysprop5import io.kotest.property.classifications.LabelsReporter6import io.kotest.property.classifications.StandardLabelsReporter7/**8 * Global object containing settings for property testing.9 */10object PropertyTesting {11 var maxFilterAttempts: Int by AtomicProperty {12 1013 }14 var shouldPrintShrinkSteps: Boolean by AtomicProperty {15 sysprop("kotest.proptest.output.shrink-steps", true)16 }17 var shouldPrintGeneratedValues: Boolean by AtomicProperty {18 sysprop("kotest.proptest.output.generated-values", false)19 }20 var edgecasesBindDeterminism: Double by AtomicProperty {21 sysprop("kotest.proptest.arb.edgecases-bind-determinism", 0.9)22 }23 var defaultSeed: Long? by AtomicProperty {24 sysprop("kotest.proptest.default.seed", null) { it.toLong() }25 }26 var defaultMinSuccess: Int by AtomicProperty {27 sysprop("kotest.proptest.default.min-success", Int.MAX_VALUE)28 }29 var defaultMaxFailure: Int by AtomicProperty {30 sysprop("kotest.proptest.default.max-failure", 0)31 }32 var defaultIterationCount: Int by AtomicProperty {33 sysprop("kotest.proptest.default.iteration.count", 1000)34 }35 var defaultShrinkingMode: ShrinkingMode by AtomicProperty {36 ShrinkingMode.Bounded(1000)37 }38 var defaultListeners: List<PropTestListener> by AtomicProperty {39 listOf()40 }41 var defaultEdgecasesGenerationProbability: Double by AtomicProperty {42 sysprop("kotest.proptest.arb.edgecases-generation-probability", 0.02)43 }44 var defaultOutputClassifications: Boolean by AtomicProperty {45 sysprop("kotest.proptest.arb.output.classifications", false)46 }47 var failOnSeed: Boolean by AtomicProperty {48 sysprop("kotest.proptest.seed.fail-if-set", false)49 }50 var writeFailedSeed: Boolean by AtomicProperty {51 sysprop("kotest.proptest.seed.write-failed", true)52 }53}54fun EdgeConfig.Companion.default(): EdgeConfig = EdgeConfig(55 edgecasesGenerationProbability = PropertyTesting.defaultEdgecasesGenerationProbability56)57data class PropTest(58 val seed: Long? = PropertyTesting.defaultSeed,59 val minSuccess: Int = PropertyTesting.defaultMinSuccess,60 val maxFailure: Int = PropertyTesting.defaultMaxFailure,61 val shrinkingMode: ShrinkingMode = PropertyTesting.defaultShrinkingMode,62 val iterations: Int? = null,63 val listeners: List<PropTestListener> = PropertyTesting.defaultListeners,64 val edgeConfig: EdgeConfig = EdgeConfig.default(),65 val constraints: Constraints? = null,66)67fun PropTest.toPropTestConfig() =68 PropTestConfig(69 seed = seed,70 minSuccess = minSuccess,71 maxFailure = maxFailure,72 iterations = iterations,73 shrinkingMode = shrinkingMode,74 listeners = listeners,75 edgeConfig = edgeConfig76 )77/**78 * Property Test Configuration to be used by the underlying property test runner79 *80 * @param iterations The number of iterations to run. If null either the global [PropertyTesting]'s default value81 * will be used, or the minimum iterations required for the supplied generations. Whichever is82 * greater.83 *84 * @param constraints controls the loop for properties. See [Constraints].85 */86@OptIn(ExperimentalKotest::class)87data class PropTestConfig(88 val seed: Long? = PropertyTesting.defaultSeed,89 val minSuccess: Int = PropertyTesting.defaultMinSuccess,90 val maxFailure: Int = PropertyTesting.defaultMaxFailure,91 val shrinkingMode: ShrinkingMode = PropertyTesting.defaultShrinkingMode,92 val iterations: Int? = null,93 val listeners: List<PropTestListener> = PropertyTesting.defaultListeners,94 val edgeConfig: EdgeConfig = EdgeConfig.default(),95 val outputClassifications: Boolean = PropertyTesting.defaultOutputClassifications,96 val labelsReporter: LabelsReporter = StandardLabelsReporter,97 val constraints: Constraints? = null,98)99interface PropTestListener {100 suspend fun beforeTest(): Unit = Unit101 suspend fun afterTest(): Unit = Unit102}

Full Screen

Full Screen

LabelsReporter.kt

Source:LabelsReporter.kt Github

copy

Full Screen

...6/**7 * Pluggable interface for outputting input value labels used in property testing.8 */9@ExperimentalKotest10interface LabelsReporter {11 fun output(result: PropertyResult)12}13@ExperimentalKotest14object StandardLabelsReporter : LabelsReporter {15 private fun row(label: String, count: Int, attempts: Int, countPad: Int) {16 val percentage = max(((count / attempts.toDouble() * 100.0)).roundToInt(), 1)17 println("${label.padEnd(60, ' ')} ${count.toString().padStart(countPad, ' ')} ($percentage%)")18 }19 override fun output(result: PropertyResult) {20 val countPad = result.attempts.toString().length21 result.inputs.forEach { arg ->22 println("Label statistics for arg $arg (${result.attempts} inputs):")23 result.labels[arg]?.forEach { (label, count) ->24 row(label, count, result.attempts, countPad)25 }26 val other = result.attempts - (result.labels[arg]?.values?.sum() ?: 0)27 if (other > 0) {28 row("OTHER", other, result.attempts, countPad)...

Full Screen

Full Screen

output.kt

Source:output.kt Github

copy

Full Screen

1package io.kotest.property.classifications2import io.kotest.property.PropTestConfig3import io.kotest.property.PropertyContext4import io.kotest.property.PropertyResult5import io.kotest.property.PropertyTesting6fun PropertyContext.outputClassifications(inputs: Int, config: PropTestConfig, seed: Long) {7 val result =8 PropertyResult(List(inputs) { it.toString() }, seed, attempts(), successes(), failures(), autoclassifications())9 if (config.outputClassifications) config.labelsReporter.output(result)10}...

Full Screen

Full Screen

LabelsReporter

Using AI Code Generation

copy

Full Screen

1val reporter = LabelsReporter()2val config = PropertyTestingConfig(reporter = reporter)3val reporter = LabelsReporter()4val config = PropertyTestingConfig(reporter = reporter)5val reporter = LabelsReporter()6val config = PropertyTestingConfig(reporter = reporter)7val reporter = LabelsReporter()8val config = PropertyTestingConfig(reporter = reporter)9val reporter = LabelsReporter()10val config = PropertyTestingConfig(reporter = reporter)11val reporter = LabelsReporter()12val config = PropertyTestingConfig(reporter = reporter)13val reporter = LabelsReporter()14val config = PropertyTestingConfig(reporter = reporter)15val reporter = LabelsReporter()16val config = PropertyTestingConfig(reporter = reporter)17val reporter = LabelsReporter()18val config = PropertyTestingConfig(reporter = reporter)19val reporter = LabelsReporter()20val config = PropertyTestingConfig(reporter = reporter)21val reporter = LabelsReporter()22val config = PropertyTestingConfig(reporter = reporter)23val reporter = LabelsReporter()24val config = PropertyTestingConfig(reporter = reporter)25val reporter = LabelsReporter()26val config = PropertyTestingConfig(reporter = reporter)27val reporter = LabelsReporter()28val config = PropertyTestingConfig(reporter = reporter)29val reporter = LabelsReporter()30val config = PropertyTestingConfig(reporter = reporter)

Full Screen

Full Screen

LabelsReporter

Using AI Code Generation

copy

Full Screen

1val result = forAll(1000, Gen.int(), Gen.int()) { a, b ->2}3println(result.classifications())4LabelsReporter: LabelsReporter(5labels = [LabelsReporter.Label(name=shrinking, count=0, labels=[]), LabelsReporter.Label(name=success, count=1000, labels=[])],6val result = forAll(1000, Gen.int(), Gen.int()) { a, b ->7}8println(result.classifications())9LabelsReporter: LabelsReporter(10labels = [LabelsReporter.Label(name=shrinking, count=0, labels=[]), LabelsReporter.Label(name=success, count=1000, labels=[])],

Full Screen

Full Screen

LabelsReporter

Using AI Code Generation

copy

Full Screen

1val reporter = LabelsReporter()2val result = property(config = PropertyConfig(reporter = reporter), prop = ::myProperty).check()3println(reporter.labels)4val result = property(config = PropertyConfig(reporter = LabelsReporter()), prop = ::myProperty).check()5println(result.labels)6val result = property(config = PropertyConfig(reporter = LabelsReporter()), prop = ::myProperty).check()7println(result.labels)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in LabelsReporter

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful