### Compacted Test Failure Report Output Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Example of the console output generated when a compacted test series fails. ```text java.lang.AssertionError: ΣString Summary: 1 OK, 7 failed Error: 1: 4: expected: but was:<4> Error: 2: one: expected: but was: Error: 3: null: Expected "three" but actual was null Error: 4: null: Expected "three" but actual was null Error: 5: null: Expected "three" but actual was null Error: 6: two: expected: but was: OK: 7: three Error: 8: four: expected: but was: ---------------------------------------- ``` -------------------------------- ### Compacted Test Progress Heartbeat Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Example of the periodic progress output printed during long-running compacted test series. ```text ΣByteArray: compact progress: 124/1000000 completed, 3 failed ``` -------------------------------- ### Configure Matrix Suites with Data Layers Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Shows how to configure execution modes and name functions within a matrixSuite. ```kotlin val dataDrivenMatrix by matrixSuite(matrixConfig { execution = ExecutionMode.Sequential }) { data("numbers", listOf(1, 2, 3), nameFn = { index, value -> "$index: n=$value" }) test { number -> number shouldBeGreaterThan 0 } data("lazy values", generateSequence(1) { it + 1 }, limit = 3) { execution = ExecutionMode.Concurrent(parallelism = 2) } test { number -> number shouldBeGreaterThan 0 } data("string data", listOf("foo", "bar")) - { word -> "has a length" { word.length shouldBeGreaterThan 0 } } } ``` -------------------------------- ### Define a matrix test suite Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Demonstrates the basic structure of a matrixSuite using data and property layers. ```kotlin val quickstart by matrixSuite(matrixConfig { execution = ExecutionMode.Sequential }) { data("input", listOf("foo", "bar")) - { input -> property("offset", Arb.int(0..100), iterations = 25) test { offset -> val result = "$input-$offset" result.startsWith(input) shouldBe true } } } ``` -------------------------------- ### Configure fixtures within a matrix suite Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Shows how to use fixtures inside matrix suites and compact blocks, illustrating how they interact with data layers and concurrency settings. ```kotlin val fixtureMatrix by matrixSuite(matrixConfig { execution = ExecutionMode.Concurrent() }) { fixture { Random.nextBytes(16) } - { "regular test with fresh bytes" { bytes -> // fresh value, this test only bytes.size shouldBe 16 } "suite with a shared fixture" - { bytes -> // one value for the whole suite; `- { }` opens a matrix scope, data("word", listOf("foo", "bar")) test { word -> // so data/property/compact layers are available here bytes.isNotEmpty() shouldBe true word.length shouldBeGreaterThan 0 } } } // Fixtures also work inside compact blocks — same parameter, same freshness rules: compact("compact checks with fresh fixture") { report = CompactReport.AllCases } - { fixture { Random.nextBytes(16) } - { "fresh bytes per row" { bytes -> bytes.size shouldBe 16 } } } } ``` -------------------------------- ### Define and use a basic fixture Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Demonstrates how to declare a fixture and access the generated value as a parameter in nested tests and suites. ```kotlin fixture { Random.nextBytes(16) } - { // ^ open the fixture scope with `- { }` "a single test" { bytes -> // <-- `bytes` is the fixture, freshly generated for THIS test bytes.size shouldBe 16 } "a nested suite" - { bytes -> // <-- `bytes` is one fixture, shared by everything in this suite data("word", listOf("foo", "bar")) test { word -> bytes.isNotEmpty() shouldBe true } } } ``` -------------------------------- ### Configure Kotlin for Context Parameters Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Add the -Xcontext-parameters compiler argument to your build.gradle.kts to enable the required language features. ```kotlin // build.gradle.kts kotlin { compilerOptions { freeCompilerArgs.add("-Xcontext-parameters") } } ``` -------------------------------- ### Configure Project-wide TestSession Defaults Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Define global matrix defaults by extending TestSession with a custom TestConfig. ```kotlin object ProjectTestSessionConfig : TestSession(testConfig = TestConfig.apply { MatrixTestDefaults { execution = ExecutionMode.Sequential defaultPropertyIterations = 250 defaultCompactConcurrency = CompactConcurrency.Shared(16) defaultCompactReport = CompactReport.FailuresOnly defaultCompactReportRows = 128 defaultProgressIndicator = Indicator.Heartbeat(every = 2.seconds) } }) ``` -------------------------------- ### Define Data-Driven Matrix Layers Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Demonstrates using .asData() on collections to define test rows and dimensions. ```kotlin listOf(1, 2, 3).asData() test { it shouldBeGreaterThan 0 } mapOf("dev" to 8080, "prod" to 443).asData(nameFn = { (env, _) -> env }) - { (env, port) -> /* … */ } ``` -------------------------------- ### Data-Driven Testing with TestBalloon Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Create data-driven test suites using the withData API. Use the minus operator to create a suite and enable compact mode to prevent heap exhaustion. ```kotlin val aDataDrivenSuite by testSuite { // -> NOTE the minus ↙↙↙, it creates a suite withData(1, 2, 3, 4) - { number -> // Will create only a single test, but the error will contain all failed inputs withData("one", "two", "three", "four", compact = true) { word -> //your test logic being run 16 times } } } ``` -------------------------------- ### Configure Matrix Compaction Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Collapses virtual subtrees into a single test report to manage large test trees. Use this to control concurrency, reporting verbosity, and progress tracking. ```kotlin val compactMatrix by matrixSuite(matrixConfig { execution = ExecutionMode.Concurrent() }) { compact("all generated checks") { concurrency = CompactConcurrency.Shared(16) report = CompactReport.FailuresOnly reportRows = 256 progressIndicator = Indicator.Heartbeat(every = 1.seconds) } - { data("word", listOf("foo", "bar", "baz")) - { word -> property("number", Arb.int(0..100), iterations = 100) test { number -> (word.length + number) shouldBeGreaterThan 0 } } } } ``` -------------------------------- ### Define a Matrix Test Suite Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Configures a matrix suite with concurrent execution, fixtures, data-driven parameters, and property-based testing. ```kotlin val combinedFeaturesSuite by matrixSuite(matrixConfig { execution = ExecutionMode.Concurrent(12) }) { fixture { Random.nextBytes(16) } - { "data, properties, fixtures, and compact reports" - { freshBytes -> data("multiplier", listOf(1, 2, 3)) - { multiplier -> compact("generated checks") { report = CompactReport.FailuresOnly } - { property("offset", Arb.int(0..100), iterations = 50) test { offset -> val result = freshBytes.size * multiplier + offset result shouldBeGreaterThan 0 } } } } } } ``` -------------------------------- ### Antipattern for Fixture Generation Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Illustrates an incorrect nesting of fixture generators that will cause runtime errors. ```kotlin val outermostSuite by testSuite { withFixtureGenerator(random::nextFloat) - { testSuite("outer") { /*fixture implicitly available as `it`*/ test("nested") { float -> /**`it` is not available, explicit parameter specification messes things up*/ //This will throw a runtime error, because "nested" will be erroneously wired directly below the outermos suite } } } } ``` -------------------------------- ### Compare named and equivalent layer structures Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Shows how a named layer is shorthand for wrapping a nameless layer in a labeled suite. ```kotlin data("numbers", listOf(1, 2, 3)) - { /* … */ } // named layer "numbers" - { // equivalent structure data(listOf(1, 2, 3)) - { /* … */ } } ``` -------------------------------- ### Generating Test Fixtures Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Demonstrates various ways to use withFixtureGenerator to provide fresh data for tests and suites, including random seeds and object instantiation. ```kotlin import at.asitplus.testballoon.withFixtureGenerator //<- Look ma, only a single import! import de.infix.testBalloon.framework.core.testSuite import kotlin.random.Random import kotlinx.coroutines.delay //just to get some suspending demo generator val aGeneratingSuite by testSuite { //seed before the generator function, not inside! val byteRNG = Random(42); //We want to test with fresh randomness, so we generate a fresh fixture for each test withFixtureGenerator { byteRNG.nextBytes(32) } - { repeat(5) { test("Generated test with fresh randomness") { freshFixture -> //your test logic here } } testSuite("Generated Suite with fresh randomness") { freshFixture -> test("using the outer fixture") { //your logic based on freshFixture here } } repeat(5) { //✨ it ✨ just ✨ werks ✨ test("Test with implicit fixture name `it`") { //do something with `it`, it contains fresh randomness! } } } //seed the RNG for reproducible tests val random = Random(42) //reference function to be called for each test inside withFixtureGenerator withFixtureGenerator(random::nextFloat) - { repeat(10) { test("Generated test with random float") { //test something floaty! } } test("And some other test that des not conform to the shema from the loop") { //test something different, with a fresh float } } //always-the-same fixtures also work, of course withFixtureGenerator { object { var a: Int = 1 val b: Int = 2 } } - { test("one") { it.a++ //and we can even modify them in one test println("a=${it.a}, b=${it.b}") //a=2, b=2 } test("two") { //without affecting the other! println("a=${it.a}, b=${it.b}") //a=1, b=2 } } //Let's test some nasty bug that shows itself only sometimes functionality val ageRNG = Random(seed = 26) withFixtureGenerator { class ABuggyImplementation(val age: Int) { fun restrictedAction(): Boolean = if (age < 18) false else if (age > 18) true else Random.nextBoolean() //introduce jitter to simulate a faulty implementation } //create new object for each test ABuggyImplementation(ageRNG.nextInt(0, 99)) } - { repeat(1000) { test("Generated test accessing restricted resources") { //test `restrictedAction` across a wide age range //a thousand times to unveil the bug } } } } ``` -------------------------------- ### Combine FreeSpec with FixtureGen Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Integrate fixture generation into your FreeSpec suites to provide fresh data to tests. ```kotlin import at.asitplus.testballoon.withFixtureGenerator // <- Look ma, only regular generatingFixture import! import at.asitplus.testballoon.invoke // <- Look ma, only regular freespec import! import at.asitplus.testballoon.minus // <- Look ma, only regular freespec import! import de.infix.testBalloon.framework.core.testSuite import kotlin.random.Random val aGeneratingFreeSpecSuite by testSuite { //any lambda with any return type is a fixture generator. Type is reified. withFixtureGenerator { Random.nextBytes(32) } - { "A Suite with fresh randomness" - { freshFixture -> "Consuming outer fixture" { //your freshFixture-based test logic here } withFixtureGenerator { Random.nextBytes(32) } - { "With fresh inner fixture" { inner -> //your test logic here with always fresh inner //and fixed freshFixture from outer scope } } } repeat(100) { "Generated test with fresh randomness" { freshFixture -> //some more test logic; each call gets fresh randomness } } //parameter must be explicitly specified to disambiguate "Test with fixture name `it`" { it -> //no need for an explicit parameter name here, just use `it` } "And we can even nest!" - { withFixtureGenerator { Random.nextBytes(16) } - { repeat(10) { "pure, high-octane magic going on" { it -> //Woohoo! more randomness each run } } } } } } ``` -------------------------------- ### Configure Matrix Suites with Explicit TestConfig Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Apply specific execution modes and test configurations to suites and tests, including disabling specific nodes with a bang prefix. ```kotlin val configuredMatrix by matrixSuite(matrixConfig { execution = ExecutionMode.Concurrent(parallelism = 4) defaultPropertyIterations = 50 }) { test("explicit test", testConfig = TestConfig) { // green code } testSuite("explicit suite", testConfig = TestConfig) { "bare FreeSpec-style test"(testConfig = TestConfig) { // green code } } "!temporarily disabled" { error("will not run") } } ``` -------------------------------- ### Define a FreeSpec Test Suite Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Use the testSuite builder to define nested test structures with custom configurations. ```kotlin import at.asitplus.testballoon.invoke import at.asitplus.testballoon.minus import de.infix.testBalloon.framework.core.TestConfig import de.infix.testBalloon.framework.core.TestInvocation import de.infix.testBalloon.framework.core.invocation import de.infix.testBalloon.framework.core.singleThreaded import de.infix.testBalloon.framework.core.testSuite val aFreeSpecSuite by testSuite { //testConfigs are supported for suites "The outermost blue code"(testConfig = TestConfig.singleThreaded()) - { "contains some more blue code" - { ", some green code inside the lambda" { // your test logic here } //testConfigs are supported for Tests ", and some more green code inside the second lambda"(testConfig = TestConfig.invocation(TestInvocation.SEQUENTIAL)) { // more test logic here } } "And finally some more blue code" - { "!With some final disabled green code in this lambda" { //additional, disabled test logic here } } } } ``` -------------------------------- ### Define Property Matrix Layers Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Integrates Kotest generators into a matrix suite for property-based testing. ```kotlin val propertyMatrix by matrixSuite(matrixConfig { defaultPropertyIterations = 100 }) { property("bytes", Arb.byteArray(Arb.int(1, 64), Arb.byte())) { seed = 0xC0FFEE nameFn = { index, bytes -> "$index: ${bytes.size} bytes" } } test { bytes -> bytes.toHexString(HexFormat.UpperCase).hexToByteArray() shouldBe bytes } } ``` -------------------------------- ### Property Testing with TestBalloon Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Generate test data using checkAll, which integrates with kotest-property. Use compact mode to aggregate test results and avoid excessive memory usage. ```kotlin val propertySuite by testSuite { // DON'T generate a suite for each item. Instead: aggregate >->-->------↘↘↘↘↘↘↘↘↘↘↘↘ checkAll(iterations = 100, Arb.byteArray(Arb.int(100, 200), Arb.byte()), compact = true) - { byteArray -> checkAll(iterations = 10, Arb.uLong()) { number -> //test with byte arrays and number for fun and profit } } checkAll(iterations = 100, Arb.byteArray(Arb.int(100, 200), Arb.byte())) - { byteArray -> checkAll(iterations = 10, Arb.uLong()) { number -> //test with byte arrays and number for fun and profit } } } ``` -------------------------------- ### Apply TestConfig to Data Layers Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Wrap data layers in a testSuite to apply TestConfig settings like aroundAll or aroundEach to individual cases. ```kotlin testSuite("with shared setup", testConfig = TestConfig.aroundAll { action -> // one-time setup around every case of this layer action() }) { data(listOf("foo", "bar", "baz")) test { word -> word.length shouldBeGreaterThan 0 } } ``` -------------------------------- ### Define Nested Matrix Execution Scopes Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Use matrixConfig to define concurrency levels for specific test suites and individual tests. ```kotlin val perScopeConfig by matrixSuite(matrixConfig { execution = ExecutionMode.Sequential }) { // run just this group's children concurrently (also auto-disables the TestScope — see the concurrency note above) testSuite("heavy group", matrixConfig { execution = ExecutionMode.Concurrent(8) }) { data(1..1000) test { /* … */ } } "freespec group"(matrixConfig { execution = ExecutionMode.Concurrent(4) }) - { "child" { /* … */ } } test("one heavy test", matrixConfig { execution = ExecutionMode.Concurrent(2) }) { /* … */ } } ``` -------------------------------- ### Replay Matrix Failures Source: https://github.com/a-sit-plus/testballoon-addons/blob/main/README.md Uses the 'Error replay info' from a failed test to isolate and re-run specific failing combinations. Apply the recorded seeds and indices back to the corresponding property or data layers. ```kotlin val replay by matrixSuite { property("first", Arb.int(), replay = Cases(seed = 4779463605442148766L, iter = 4L)) - { first -> property("second", Arb.double(), replay = Cases(seed = -1353176301820643450L, iter = 2L)) - { second -> data("third", listOf(1, 2, 3, 4, 5), replay = Indexes(1L)) - { third -> property("fourth", Arb.byte(), replay = Cases(seed = 5014696554795393980L, iter = 3L)) test { fourth -> // now runs only the single failing combination } } } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.