How to use compareJsonOptions method of io.kotest.assertions.json.CompareJsonOptions class

Best Kotest code snippet using io.kotest.assertions.json.CompareJsonOptions.compareJsonOptions

compare.kt

Source:compare.kt Github

copy

Full Screen

...47/**48 * helper method for bridging old compare options into new49 */50internal fun legacyOptions(mode: CompareMode, order: CompareOrder) =51   compareJsonOptions {52      typeCoercion = when (mode) {53         CompareMode.Strict -> TypeCoercion.Disabled54         CompareMode.Lenient -> TypeCoercion.Enabled55      }56      propertyOrder = when (order) {57         CompareOrder.Strict -> PropertyOrder.Strict58         CompareOrder.Lenient -> PropertyOrder.Lenient59      }60   }61internal val defaultCompareJsonOptions = CompareJsonOptions()62class CompareJsonOptions(63   /**64    * Controls whether property order must be identical65    */66   var propertyOrder: PropertyOrder = PropertyOrder.Lenient,67   /**68    * Controls whether array ordering must be identical.69    */70   var arrayOrder: ArrayOrder = ArrayOrder.Strict,71   /**72    * Controls whether the actual document may contain extra fields or not.73    */74   var fieldComparison: FieldComparison = FieldComparison.Strict,75   /**76    * Controls whether number formatting should be taken into consideration. For instance, comparing 1.00 to 1.0, or77    * 1E2 to 10078    */79   var numberFormat: NumberFormat = NumberFormat.Lenient,80   /**81    *  Controls whether types should be coerced when possible. For instance, when strings contain bool or numeric values.82    */83   var typeCoercion: TypeCoercion = TypeCoercion.Disabled84)85enum class PropertyOrder {86   /**87    * Default. Property order in objects does not matter.88    *89    * Example: `"""{ "a": 0, "b": 2 }""".shouldEqualJson("""{ "b": 2, "a": 1 }""", compareJsonOptions { propertyOrder = Lenient })` will pass90    */91   Lenient,92   /**93    * Properties must be in same order. E.g. `{ "a": 0, "b": 2 }` is not considered equal to `{ "b": 2, "a": 1 }`94    */95   Strict96}97enum class ArrayOrder {98   /**99    * Default. Arrays must contain the same elements in the same order.100    */101   Strict,102   /**103    * Arrays are allowed to be shuffled, but must still contain same items.104    */105   Lenient,106}107enum class FieldComparison {108   /**109    * Default. Objects in [expected] and [actual] must contain the same fields.110    */111   Strict,112   /**113    * Objects in the actual document may contain extraneous fields without causing comparison to fail.114    */115   Lenient,116}117enum class NumberFormat {118   /**119    * Default. Numbers will be interpreted before being compared. Meaning we can compare 0E3 to 1000 without fail120    */121   Lenient,122   /**123    * Numbers must also be formatted the same way to be considered equal.124    */125   Strict126}127enum class TypeCoercion {128   /**129    * Default. Types will not be converted. Meaning `"true"` and `true` are considered unequal.130    */131   Disabled,132   /**133    * Types may be coerced. Strings containing numbers will be considered equal to their numbers, and booleans in134    * strings will also be compared.135    *136    * For example: `"\"11\"".shouldEqualJson("12", compareJsonOptions { typeCoercion = TypeCoercion.Enabled })` will137    * succeed.138    */139   Enabled;140   internal fun isEnabled(): Boolean =141      this == Enabled142}143fun compareJsonOptions(builder: CompareJsonOptions.() -> Unit): CompareJsonOptions =144   CompareJsonOptions().apply(builder)145/**146 * Compares two json trees, returning a detailed error message if they differ.147 */148internal fun compare(149   path: List<String>,150   expected: JsonNode,151   actual: JsonNode,152   options: CompareJsonOptions153): JsonError? {154   return when (expected) {155      is JsonNode.ObjectNode -> when (actual) {156         is JsonNode.ObjectNode -> compareObjects(path, expected, actual, options)157         else -> JsonError.ExpectedObject(path, actual)...

Full Screen

Full Screen

JsonLiteralsTest.kt

Source:JsonLiteralsTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.tests.json2import io.kotest.assertions.json.NumberFormat3import io.kotest.assertions.json.TypeCoercion4import io.kotest.assertions.json.compareJsonOptions5import io.kotest.assertions.json.shouldEqualJson6import io.kotest.assertions.shouldFail7import io.kotest.assertions.throwables.shouldThrow8import io.kotest.core.spec.style.FunSpec9import io.kotest.matchers.string.shouldContain10import io.kotest.matchers.throwable.shouldHaveMessage11class JsonLiteralsTest : FunSpec(12   {13      test("Unsupported type") {14         shouldThrow<IllegalArgumentException> {15            "0x03" shouldEqualJson "0x03"16         }.shouldHaveMessage("Unsupported kotlinx-serialization type 0x03")17      }18      context("Strict (default) comparisons") {19         test("comparing float and int") {20            shouldFail {21               "3.2" shouldEqualJson "3"22            }.shouldHaveMessage(23               """24               The top level expected 3 but was 3.225               expected:<3> but was:<3.2>26               """.trimIndent()27            )28         }29         test("quoted numbers are treated as strings") {30            shouldFail { "\"1E3\"" shouldEqualJson "1000.0" }31            // Unquoted 1E3 is parsed to double and back due to prettifying output32            shouldFail { "\"1000.0\"" shouldEqualJson "1E3" }.message shouldContain33               "The top level expected number but was string"34            shouldFail { "10.0" shouldEqualJson "\"10.0\"" }.message shouldContain35               "The top level expected string but was number"36         }37         test("comparing exponent-based float with regular float") {38            "1E3" shouldEqualJson "1000.0"39            "1000.0" shouldEqualJson "1E3"40            "1000.0" shouldEqualJson "1000"41            "5E0" shouldEqualJson "5.0"42            "2E-1" shouldEqualJson "0.2"43            shouldFail {44               "1.0E-3" shouldEqualJson "0.0001"45            }46            "1.0E-4" shouldEqualJson "0.0001"47         }48         test("comparing high-precision floating point numbers") {49            // Note: In the middle paragraph of the failure message the expected JSON has been50            //       formatted as a JSON tree using KotlinX.serialization which parses the51            //       number to a double and back, hence the loss of precision.52            shouldFail {53               "0.12345678912345678" shouldEqualJson "0.123456789123456789"54            }.shouldHaveMessage(55               """56               The top level expected 0.123456789123456789 but was 0.1234567891234567857               expected:<0.123456789123456789> but was:<0.12345678912345678>58               """.trimIndent()59            )60         }61         test("comparing string and boolean") {62            shouldFail {63               "true" shouldEqualJson "\"true\""64            }.shouldHaveMessage(65               """66               The top level expected string but was boolean67               expected:<"true"> but was:<true>68               """.trimIndent()69            )70         }71      }72      context("CompareMode.Exact requires same format for numbers") {73         infix fun String.shouldExactlyEqualJson(expected: String) =74            this.shouldEqualJson(expected, compareJsonOptions { numberFormat = NumberFormat.Strict })75         test("comparing float and exponent") {76            shouldFail {77               "10.0" shouldExactlyEqualJson "1e1"78            }.shouldHaveMessage(79               """80               The top level expected 1e1 but was 10.081               expected:<1e1> but was:<10.0>82               """.trimIndent()83            )84         }85         test("comparing int and exponent") {86            shouldFail {87               "10" shouldExactlyEqualJson "1e1"88            }.shouldHaveMessage(89               """90               The top level expected 1e1 but was 1091               expected:<1e1> but was:<10>92               """.trimIndent()93            )94         }95         test("comparing float and int") {96            shouldFail {97               "10.0" shouldExactlyEqualJson "10"98            }.shouldHaveMessage(99               """100               The top level expected 10 but was 10.0101               expected:<10> but was:<10.0>102               """.trimIndent()103            )104         }105         test("quoted numbers are treated as strings") {106            shouldFail { "\"1E3\"" shouldEqualJson "1000.0" }107            // Unquoted 1E3 is parsed to double and back due to prettifying output108            shouldFail { "\"1000.0\"" shouldEqualJson "1E3" }.message shouldContain109               "The top level expected number but was string"110            shouldFail { "10.0" shouldEqualJson "\"10.0\"" }.message shouldContain111               "The top level expected string but was number"112         }113      }114      context("Lenient type-conversions") {115         infix fun String.lenientShouldEqualJson(expected: String) =116            this.shouldEqualJson(expected, compareJsonOptions { typeCoercion = TypeCoercion.Enabled })117         test("comparing exponent-based float with regular float") {118            "1E3" lenientShouldEqualJson "\"1000.0\""119            "1000.0" lenientShouldEqualJson "\"1E3\""120            "2E-1" lenientShouldEqualJson "0.2"121            "2E-1" lenientShouldEqualJson "\"0.2\""122            "0.2" lenientShouldEqualJson "\"2e-1\""123            "5E0" lenientShouldEqualJson "5.0"124         }125         test("Strings with numbers") {126            shouldFail {127               "\"abc 123\"" lenientShouldEqualJson "123"128            }.shouldHaveMessage(129               """130                  The top level expected number but was string...

Full Screen

Full Screen

JsonMatchers.kt

Source:JsonMatchers.kt Github

copy

Full Screen

1package io.kotest.assertions.json2import io.kotest.matchers.ComparableMatcherResult3import io.kotest.matchers.Matcher4import io.kotest.matchers.MatcherResult5import io.kotest.matchers.should6import io.kotest.matchers.shouldNot7import kotlinx.serialization.ExperimentalSerializationApi8import kotlinx.serialization.json.Json9import kotlinx.serialization.json.JsonArray10import kotlinx.serialization.json.JsonElement11import kotlinx.serialization.json.JsonObject12import kotlin.reflect.KClass13@OptIn(ExperimentalSerializationApi::class)14internal val pretty by lazy { Json { prettyPrint = true; prettyPrintIndent = "  " } }15/**16 * Verifies that the [expected] string is valid json, and that it matches this string.17 *18 * This matcher will consider two json strings matched if they have the same key-values pairs,19 * regardless of order.20 *21 */22infix fun String?.shouldMatchJson(expected: String?) = this should matchJson(expected)23infix fun String?.shouldNotMatchJson(expected: String?) = this shouldNot matchJson(expected)24@OptIn(ExperimentalSerializationApi::class)25fun matchJson(expected: String?) = object : Matcher<String?> {26   override fun test(value: String?): MatcherResult {27      val actualJson = try {28         value?.let(pretty::parseToJsonElement)29      } catch (ex: Exception) {30         return MatcherResult(31            false,32            { "expected: actual json to be valid json: $value" },33            {34               "expected: actual json to be invalid json: $value"35            })36      }37      val expectedJson = try {38         expected?.let(pretty::parseToJsonElement)39      } catch (ex: Exception) {40         return MatcherResult(41            false,42            { "expected: expected json to be valid json: $expected" },43            { "expected: expected json to be invalid json: $expected" }44         )45      }46      return ComparableMatcherResult(47         actualJson == expectedJson,48         { "expected json to match, but they differed\n\n" },49         { "expected not to match with: $expectedJson but match: $actualJson" },50         actualJson.toString(),51         expectedJson.toString()52      )53   }54}55@OptIn(ExperimentalSerializationApi::class)56fun beValidJson() = object : Matcher<String?> {57   override fun test(value: String?): MatcherResult {58      return try {59         value?.let(pretty::parseToJsonElement)60         MatcherResult(61              true,62              { "expected: actual json to be valid json: $value" },63              { "expected: actual json to be invalid json: $value" }64         )65      } catch (ex: Exception) {66         MatcherResult(67              false,68              { "expected: actual json to be valid json: $value" },69              { "expected: actual json to be invalid json: $value" }70         )71      }72   }73}74@OptIn(ExperimentalSerializationApi::class)75fun beJsonType(kClass: KClass<*>) = object : Matcher<String?> {76   override fun test(value: String?): MatcherResult {77      val element = try {78         value?.let(pretty::parseToJsonElement)79      } catch (ex: Exception) {80         return MatcherResult(81            false,82            { "expected: actual json to be valid json: $value" },83            { "expected: actual json to be invalid json: $value" }84         )85      }86      return MatcherResult(87         kClass.isInstance(element),88         { "expected: $value to be valid json of type: ${kClass.simpleName}" },89         { "expected: $value to not be of type: ${kClass.simpleName}" }90      )91   }92}93/**94 * Verifies that the [expected] string is valid json, and that it matches this string.95 *96 * This matcher will consider two json strings matched if they have the same key-values pairs,97 * regardless of order.98 *99 */100fun String.shouldEqualJson(expected: String, mode: CompareMode, order: CompareOrder) =101   this.shouldEqualJson(expected, legacyOptions(mode, order))102fun String.shouldEqualJson(expected: String, options: CompareJsonOptions) {103   val (e, a) = parse(expected, this)104   a should equalJson(e, options)105}106fun String.shouldNotEqualJson(expected: String, mode: CompareMode, order: CompareOrder) =107   this.shouldNotEqualJson(expected, legacyOptions(mode, order))108fun String.shouldNotEqualJson(expected: String, options: CompareJsonOptions) {109   val (e, a) = parse(expected, this)110   a shouldNot equalJson(e, options)111}112fun String.shouldBeEmptyJsonArray(): String {113   this should matchJson("[]")114   return this115}116fun String.shouldBeEmptyJsonObject(): String {117   this should matchJson("{}")118   return this119}120fun String.shouldBeJsonArray(): String {121   this should beJsonType(JsonArray::class)122   return this123}124fun String.shouldNotBeJsonArray(): String {125   this shouldNot beJsonType(JsonArray::class)126   return this127}128fun String.shouldBeJsonObject(): String {129   this should beJsonType(JsonObject::class)130   return this131}132fun String.shouldNotBeJsonObject(): String {133   this shouldNot beJsonType(JsonObject::class)134   return this135}136fun String.shouldBeValidJson(): String {137   this should beValidJson()138   return this139}140fun String.shouldNotBeValidJson(): String {141   this shouldNot beValidJson()142   return this143}144internal fun parse(expected: String, actual: String): Pair<JsonTree, JsonTree> {145   val enode = pretty.parseToJsonElement(expected)146   val anode = pretty.parseToJsonElement(actual)147   val e = toJsonTree(enode)148   val a = toJsonTree(anode)149   return Pair(e, a)150}151internal fun toJsonTree(root: JsonElement) =152   with(root.toJsonNode()) {153      JsonTree(this, prettyPrint(this))154   }...

Full Screen

Full Screen

LenientOrderArrayTest.kt

Source:LenientOrderArrayTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.tests.json2import io.kotest.assertions.json.ArrayOrder3import io.kotest.assertions.json.compareJsonOptions4import io.kotest.assertions.json.shouldEqualJson5import io.kotest.assertions.shouldFail6import io.kotest.core.spec.style.FunSpec7import io.kotest.matchers.throwable.shouldHaveMessage8class LenientOrderArrayTest : FunSpec(9   {10      infix fun String.shouldEqualJsonIgnoringOrder(other: String) =11         this.shouldEqualJson(other, compareJsonOptions { arrayOrder = ArrayOrder.Lenient })12      test("simple") {13         "[1, 2]" shouldEqualJsonIgnoringOrder "[2, 1]"14      }15      test("multiple copies") {16         "[1, 2, 2]" shouldEqualJsonIgnoringOrder "[2, 1, 2]"17      }18      test("duplicates in actual") {19         shouldFail {20            "[1, 2, 2]" shouldEqualJsonIgnoringOrder "[1, 2, 0]"21         }.shouldHaveMessage(22            """23               At '[2]' has extra element '2' not found (or too few) in '[1,2,0]'24               expected:<[25                 1,...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...54   shouldEqualJson(expected, legacyOptions(CompareMode.Strict, order))55fun String.shouldNotEqualJson(expected: String, order: CompareOrder) =56   shouldNotEqualJson(expected, legacyOptions(CompareMode.Strict, order))57infix fun String.shouldEqualSpecifiedJson(expected: String) =58   shouldEqualJson(expected, compareJsonOptions { fieldComparison = FieldComparison.Lenient })59infix fun String.shouldNotEqualSpecifiedJson(expected: String) =60   shouldNotEqualJson(expected, compareJsonOptions { fieldComparison = FieldComparison.Lenient })

Full Screen

Full Screen

compareJsonOptions

Using AI Code Generation

copy

Full Screen

1+import io.kotest.assertions.json.compareJsonOptions2+import io.kotest.assertions.json.json3+import io.kotest.assertions.json.shouldMatchJson4+import io.kotest.core.spec.style.FunSpec5+import io.kotest.matchers.shouldBe6+class JsonTest : FunSpec({7+   test("compare json with options") {8+      val expected = json {9+         "address" to json {10+         }11+      }12+      val actual = json {13+         "address" to json {14+         }15+      }16+      actual shouldMatchJson expected withOptions compareJsonOptions {17+      }18+   }19+   test("compare json with options") {20+      val expected = json {21+         "address" to json {22+         }23+      }24+      val actual = json {25+         "address" to json {26+         }

Full Screen

Full Screen

compareJsonOptions

Using AI Code Generation

copy

Full Screen

1+        val json1 = """{ "name": "kotest", "age": 10 }"""2+        val json2 = """{ "name": "kotest", "age": 10 }"""3+        json1 shouldBe json2 compareJsonOptions { ignoreArrayOrder = true }4+        json1 shouldNotBe json2 compareJsonOptions { ignoreArrayOrder = true }5+        json1 shouldBe json2 compareJsonOptions { ignoreExtraElements = true }6+        json1 shouldNotBe json2 compareJsonOptions { ignoreExtraElements = true }7+        json1 shouldBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true }8+        json1 shouldNotBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true }9+        json1 shouldBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true }10+        json1 shouldNotBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true }11+        json1 shouldBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true; ignoreNullFields = true }12+        json1 shouldNotBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true; ignoreNullFields = true }13+        json1 shouldBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true; ignoreNullFields = true; ignoreStringCase = true }14+        json1 shouldNotBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true; ignoreNullFields = true; ignoreStringCase = true }15+        json1 shouldBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true; ignoreNullFields = true; ignoreStringCase = true; ignoreWhitespace = true }16+        json1 shouldNotBe json2 compareJsonOptions { ignoreExtraElements = true; ignoreArrayOrder = true; ignoreFloatingPointArithmetic = true; ignoreNullFields = true

Full Screen

Full Screen

compareJsonOptions

Using AI Code Generation

copy

Full Screen

1+    fun `test compareJsonOptions method`() {2+        val expected = """{"id":1,"name":"kotlin"}"""3+        val actual = """{"name":"kotlin","id":1}"""4+        val result = compareJsonOptions(expected, actual, CompareJsonOptions(ignoreArrayOrder = true))5+    }6+    fun `test compareJsonOptions method`() {7+        val expected = """{"id":1,"name":"kotlin"}"""8+        val actual = """{"name":"kotlin","id":1}"""9+        val result = compareJsonOptions(expected, actual, CompareJsonOptions(ignoreArrayOrder = true))10+    }11+    fun `test compareJsonOptions method`() {12+        val expected = """{"id":1,"name":"kotlin"}"""13+        val actual = """{"name":"kotlin","id":1}"""14+        val result = compareJsonOptions(expected, actual, CompareJsonOptions(ignoreArrayOrder = true))15+    }16+    fun `test compareJsonOptions method`() {17+        val expected = """{"id":1,"name":"kotlin"}"""18+        val actual = """{"name":"kotlin","id":1}"""19+        val result = compareJsonOptions(expected, actual, CompareJsonOptions(ignoreArrayOrder = true))20+    }21+    fun `test compareJsonOptions method`() {22+        val expected = """{"id":1,"name":"kotlin"}"""23+        val actual = """{"name":"kotlin","id":1}"""24+        val result = compareJsonOptions(expected, actual, CompareJsonOptions(ignoreArrayOrder = true))25+    }

Full Screen

Full Screen

compareJsonOptions

Using AI Code Generation

copy

Full Screen

1+val jsonOptions = CompareJsonOptions(2+actual fun compareJson(expected: String, actual: String) {3+    JsonMatcher(expected, jsonOptions).match(actual)4+}5+actual fun compareJson(expected: String, actual: String, options: CompareJsonOptions) {6+    JsonMatcher(expected, options).match(actual)7+}8+actual fun compareJson(expected: String, actual: String, options: JsonCompareOptions) {9+    JsonMatcher(expected, options).match(actual)10+}11+actual fun compareJson(expected: String, actual: String, options: JsonCompareMode) {12+    JsonMatcher(expected, options).match(actual)13+}14+actual fun compareJson(expected: String, actual: String, options: JsonCompareMode, mode: JsonCompareMode) {15+    JsonMatcher(expected, options, mode).match(actual)16+}17+actual fun compareJson(expected: String, actual: String, options: JsonCompareMode, mode: JsonCompareMode, mode2: JsonCompareMode) {18+    JsonMatcher(expected, options, mode, mode2).match(actual)19+}20+actual fun compareJson(expected: String, actual: String, options: JsonCompareMode, mode: JsonCompareMode, mode2: JsonCompareMode, mode3: JsonCompareMode) {21+    JsonMatcher(expected, options, mode, mode2, mode3).match(actual)22+}23+actual fun compareJson(expected: String, actual: String, options: JsonCompareMode, mode: JsonCompare

Full Screen

Full Screen

compareJsonOptions

Using AI Code Generation

copy

Full Screen

1    val json1 = """{"a":1,"b":2}"""2    val json2 = """{"b":2,"a":1}"""3    json1.shouldBeJson(json2, CompareJsonOptions(true, true, true))4    json1.shouldNotBeJson(json2, CompareJsonOptions(true, true, true))5    json1.shouldBeJsonIgnoringOrder(json2, CompareJsonOptions(true, true, true))6    json1.shouldNotBeJsonIgnoringOrder(json2, CompareJsonOptions(true, true, true))7    json1.shouldBeJsonIgnoringExtraFields(json2, CompareJsonOptions(true, true, true))8    json1.shouldNotBeJsonIgnoringExtraFields(json2, CompareJsonOptions(true, true, true))9    json1.shouldBeJsonIgnoringExtraFieldsAndOrder(json2, CompareJsonOptions(true, true, true))10    json1.shouldNotBeJsonIgnoringExtraFieldsAndOrder(json2, CompareJsonOptions(true, true, true))11}12fun testJsonAssert() {13    val json1 = """{"a":1,"b":2}"""14    val json2 = """{"b":2,"a":1}"""15    assertJsonEquals(json1, json2, CompareJsonOptions(true, true, true))16    assertJsonNotEquals(json1, json2, CompareJsonOptions(true, true, true))17    assertJsonEqualsIgnoringOrder(json1, json2, CompareJsonOptions(true, true, true))18    assertJsonNotEqualsIgnoringOrder(json1, json2, CompareJsonOptions(true, true, true))19    assertJsonEqualsIgnoringExtraFields(json1, json2, CompareJsonOptions(true, true, true))20    assertJsonNotEqualsIgnoringExtraFields(json1, json2, CompareJsonOptions(true, true, true))21    assertJsonEqualsIgnoringExtraFieldsAndOrder(json1, json2, CompareJsonOptions(true, true, true))22    assertJsonNotEqualsIgnoringExtraFieldsAndOrder(json1, json2, CompareJsonOptions(true, true, true))23}24fun testJsonDiff() {

Full Screen

Full Screen

compareJsonOptions

Using AI Code Generation

copy

Full Screen

1+        val jsonOptions = CompareJsonOptions(2+        val expectedJson = """{"a":1,"b":2}"""3+        val actualJson = """{"b":2,"a":1}"""4+        actualJson.shouldBeJson(expectedJson, jsonOptions)5+    }6+    fun `should not match jsons with different values`() {7+        val jsonOptions = CompareJsonOptions(8+        val expectedJson = """{"a":1,"b":2}"""9+        val actualJson = """{"b":3,"a":1}"""10+        shouldThrow<AssertionError> {11+            actualJson.shouldBeJson(expectedJson, jsonOptions)12+        }13+    }14+    fun `should not match jsons with different keys`() {15+        val jsonOptions = CompareJsonOptions(16+        val expectedJson = """{"a":1,"b":2}"""17+        val actualJson = """{"b":2,"c":1}"""18+        shouldThrow<AssertionError> {19+            actualJson.shouldBeJson(expectedJson, jsonOptions)20+        }21+    }22+    fun `should match jsons with different values but in permissive mode`() {23+        val jsonOptions = CompareJsonOptions(

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful