### Kotlin Truthish Detailed Error Message Example Source: https://github.com/varabyte/truthish/blob/main/README.md Illustrates a deliberately broken test case to demonstrate the detailed and helpful error messages generated by Truthish for collection mismatches. The output clearly identifies missing and extraneous elements, aiding in quick debugging. ```kotlin @Test fun testMapButIntentionallyBroken() { assertThat(listOf(1, 2, 3, 4, 5).map { square(it) }) .containsExactly(1, 4, 9, 15, 26) // <-- Ooops, messed up 16 and 25 here .inOrder() } ``` ```text A collection did not contain element(s) Expected exactly all elements from: [ 1, 4, 9, 15, 26 ] But was : [ 1, 4, 9, 16, 25 ] Missing : [ 15, 26 ] Extraneous : [ 16, 25 ] ``` -------------------------------- ### Kotlin Truthish Basic Assertions Source: https://github.com/varabyte/truthish/blob/main/README.md Demonstrates fundamental assertion methods like `isTrue()`, `isFalse()`, `isEqualTo()`, `containsExactly()`, `assertWithMessage()`, and `assertThrows()` using Truthish in Kotlin tests. These examples cover boolean checks, value equality, collection contents, custom failure messages, and exception handling. ```kotlin import com.varabyte.truthish.* fun isEven(num: Int) = (num % 2) == 0 fun square(num: Int) = (num * num) @Test fun testEvenOdd() { assertThat(isEven(1234)).isTrue() assertThat(isEven(1235)).isFalse() } @Test fun testSum() { val nums = listOf(1, 2, 3, 4, 5) assertThat(nums.sum()).isEqualTo(15) } @Test fun testMap() { assertThat(listOf(1, 2, 3, 4, 5).map { square(it) }) .containsExactly(1, 4, 9, 16, 25) .inOrder() } @Test fun customMessage() { assertWithMessage("Unexpected list size") .that(listOf(1, 2, 3, 4, 5)).hasSize(5) } @Test fun testDivideByZeroException() { val ex = assertThrows { 10 / 0 } assertThat(ex.message).isEqualTo("/ by zero") } ``` -------------------------------- ### Configure Gradle to Access Truthish Snapshots Source: https://github.com/varabyte/truthish/blob/main/README.md This snippet demonstrates how to add the Sonatype snapshots repository to your `build.gradle.kts` file. This configuration allows Gradle to resolve and download snapshot versions of Truthish artifacts, specifically for the `com.varabyte.truthish` group, enabling testing of pre-release features or bug fixes. ```Gradle (Kotlin DSL) repositories { mavenCentral() maven("https://central.sonatype.com/repository/maven-snapshots/") { mavenContent { includeGroup("com.varabyte.truthish") snapshotsOnly() } } } ``` -------------------------------- ### Kotlin Multiplatform Truthish Dependency Configuration Source: https://github.com/varabyte/truthish/blob/main/README.md Provides the `build.gradle.kts` configuration for including Truthish in a Kotlin multiplatform project. It specifies common test dependencies and demonstrates how to configure various target platforms such as JVM, JS, Wasm, Linux, macOS, Windows, Android, and iOS. ```kotlin // build.gradle.kts // Multiplatform repositories { mavenCentral() } kotlin { jvm() js { browser() nodeJs() } wasmJs { browser() nodeJs() d8() } linuxArm64() linuxX64() macosArm64() // Mac M1+ macosX64() // Mac Intel mingwX64() // Windows iosArm64() // iOS M1+ iosX64() // iOS Intel iosSimulatorArm64() androidTarget() sourceSets { commonTest.dependencies { implementation("com.varabyte.truthish:truthish:1.0.3") implementation(kotlin("test")) } } } ``` -------------------------------- ### Kotlin Android Truthish Dependency Configuration Source: https://github.com/varabyte/truthish/blob/main/README.md Details how to include Truthish dependencies in an Android project's `build.gradle.kts`. It distinguishes between `testImplementation` for host-side tests (run on the development machine) and `androidTestImplementation` for device-side tests (run on an Android device or emulator). ```kotlin // build.gradle.kts repositories { mavenCentral() } android { /* ... */ } dependencies { // ... // If used in tests that are run on the host (i.e. your dev machine) testImplementation("com.varabyte.truthish:truthish:1.0.3") // If used in tests that are run on the device androidTestImplementation("com.varabyte.truthish:truthish:1.0.3") } ``` -------------------------------- ### Kotlin Truthish Grouping Assertions with assertAll Source: https://github.com/varabyte/truthish/blob/main/README.md Shows how to use the `assertAll` function to group multiple assertions. This ensures that all checks run before any failures are reported, allowing for the collection of all errors from a single test block. ```kotlin val person = Person("Alice", 30) assertAll { that(person.name).isEqualTo("Bob") that(person.age).isEqualTo(45) } // The above will assert once, reporting both equality check failures ``` -------------------------------- ### Kotlin JVM Truthish Dependency Configuration Source: https://github.com/varabyte/truthish/blob/main/README.md Shows the `build.gradle.kts` snippet for adding Truthish as a `testImplementation` dependency in a standard Kotlin JVM project. This configuration is suitable for projects targeting only the Java Virtual Machine. ```kotlin // build.gradle.kts repositories { mavenCentral() } dependencies { // ... testImplementation(kotlin("test")) testImplementation("com.varabyte.truthish:truthish:1.0.3") } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.